码迷,mamicode.com
首页 > 编程语言 > 详细

hdu 4927 java求组合数(大数)

时间:2014-08-08 12:17:15      阅读:245      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   java   for   ar   div   new   

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();
            
        }
    }

}

 

hdu 4927 java求组合数(大数),布布扣,bubuko.com

hdu 4927 java求组合数(大数)

标签:style   blog   color   java   for   ar   div   new   

原文地址:http://www.cnblogs.com/jiangjing/p/3898803.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!