标签:des style color java 使用 os io strong
2 3 1 2 3 4 1 5 7 2
0 -5
题解及代码:
import java.util.*;
import java.io.*;
import java.math.*;
public class Main {
public static BigInteger solve(BigInteger s[],int n)
{
BigInteger ans=BigInteger.valueOf(0);
BigInteger t=BigInteger.valueOf(1);
BigInteger l=BigInteger.valueOf(1);
BigInteger r=BigInteger.valueOf(n-1);
int k=0;
for(int i=n-1;i>=0;i--)
{
if(k%2==0) ans=ans.add(t.multiply(s[i]));
else ans=ans.subtract(t.multiply(s[i]));
t=t.multiply(r).divide(l);
l=l.add(BigInteger.ONE);
r=r.subtract(BigInteger.ONE);
k++;
}
return ans;
}
public static void main(String []args)
{
int T,n;
BigInteger s[]=new BigInteger[3010];
Scanner cin = new Scanner(System.in);
T=cin.nextInt();
while(T>0)
{
T--;
n=cin.nextInt();
for(int i=0;i<n;i++)
{
s[i]=cin.nextBigInteger();
}
System.out.println(solve(s,n));
}
}
}
/*
简单计算一下:
以1 2 3 为例子
第二层为 (2-1) (3-2)
第三层为 3-2*2+1
还不是很明显,再以1 5 7 2 为例子:
第二层为 (5-1) (7-5) (2-7)
第三层为 (7-2*5+1) (2-2*7+5)
第四层为 2-3*7+3*5-1
这样我们就找到了规律,那就是计算从记过从右向左排列,
,每个数前面的系数依次为组合数,符号很奇偶。
由于计算结果比较大,使用java来计算就比较合适了。
*/
hdu 4927 Series 1,布布扣,bubuko.com
标签:des style color java 使用 os io strong
原文地址:http://blog.csdn.net/knight_kaka/article/details/38434337