标签:des style blog http color java os io
2 3 1 2 3 4 1 5 7 2
0 -5
//515MS 9976K
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner cin=new Scanner(System.in);
int t;
t=cin.nextInt();
for(int cas=1;cas<=t;cas++){
BigInteger ans=BigInteger.valueOf(0);
int n;
n=cin.nextInt();
BigInteger yanghui[]=new BigInteger[n];
BigInteger s[]=new BigInteger[n+2];
for(int i=0;i<n;i++)
s[i]=cin.nextBigInteger();
if (n == 1) {
System.out.println(s[0]);
continue;
}
yanghui[0]=BigInteger.valueOf(1);
for(int i=1;i<n;i++){
BigInteger x1=BigInteger.valueOf(i);
BigInteger x2=BigInteger.valueOf(n-i);
yanghui[i]=yanghui[i-1].multiply(x2).divide(x1);
}
boolean flag=true;
for(int i=n-1;i>=0;i--){
if(flag){ans=ans.add(yanghui[i].multiply(s[i]));flag=false;}
else {ans=ans.subtract(yanghui[i].multiply(s[i]));flag=true;}
}
System.out.println(ans);
}
}
}
HDU 4927 Series 1 杨辉三角形,布布扣,bubuko.com
标签:des style blog http color java os io
原文地址:http://blog.csdn.net/crescent__moon/article/details/38517633