hdu 4927 java求组合数(大数)

import java.util.Scanner;
import java.math.BigInteger;


public class Main {
 
    private static int [] a = new int[3005];
    private static int T;
    private static int n;
    
    public static void solve() {
        BigInteger rs = BigInteger.ZERO;
        BigInteger temp = BigInteger.ONE;
        
        rs = rs.add(BigInteger.valueOf(a[n-1]));
        n--;
        
        for(int i=1, j=n; i<=n; i++, j--) {
            temp = temp.multiply(BigInteger.valueOf(j)).divide(BigInteger.valueOf(i));
            temp = temp.multiply(BigInteger.valueOf(-1));
            rs = rs.add(temp.multiply(BigInteger.valueOf(a[j-1])));
        }
        
        System.out.println(rs);
        
    }
    
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        T = in.nextInt();
        for(int i=0; i<T; i++) {
            n = in.nextInt();
            for(int j=0; j<n; j++) {
                a[j] = in.nextInt();
            }
            
            solve();
            
        }
    }

}

 

posted on 2014-08-08 10:32  后端bug开发工程师  阅读(1405)  评论(0编辑  收藏  举报

导航