Series 1
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 269 Accepted Submission(s): 89
Problem Description
Let A be an integral series {A
1, A
2, . . . , A
n}.
The zero-order series of A is A itself.
The first-order series of A is {B 1, B 2, . . . , B n-1},where B i = A i+1 - A i.
The ith-order series of A is the first-order series of its (i - 1)th-order series (2<=i<=n - 1).
Obviously, the (n - 1)th-order series of A is a single integer. Given A, figure out that integer.
The zero-order series of A is A itself.
The first-order series of A is {B 1, B 2, . . . , B n-1},where B i = A i+1 - A i.
The ith-order series of A is the first-order series of its (i - 1)th-order series (2<=i<=n - 1).
Obviously, the (n - 1)th-order series of A is a single integer. Given A, figure out that integer.
Input
The input consists of several test cases. The first line of input gives the number of test cases T (T<=10).
For each test case:
The first line contains a single integer n(1<=n<=3000), which denotes the length of series A.
The second line consists of n integers, describing A 1, A 2, . . . , A n. (0<=A i<=10 5)
For each test case:
The first line contains a single integer n(1<=n<=3000), which denotes the length of series A.
The second line consists of n integers, describing A 1, A 2, . . . , A n. (0<=A i<=10 5)
Output
For each test case, output the required integer in a line.
Sample Input
2 3 1 2 3 4 1 5 7 2
Sample Output
0 -5
有递推关系
1 5 7 2
4 2 -5
-2 -7
-5
a[ i ][ j ]=a[i-1][j+1]-a[i-1][ j ]
这样就可以推出最后的答案
但是如果每次推,都会增加值得话
如
-1 1 -1 1
2 -2 2
-4 4
-8
如果都是这种间隔 一正一负 那就是指数级地上升了, 所以必须用大数.
而且大数计算量比较大,, 所以就不能递推来算了.
所以要找关系.
最后 我们队友找到的关系是 C(0,n-1)*a[ n ] - C(1,n-1)*a[n-1] +C(2,n-1)*a[n-2]..... ±C(n-1,n-1)*a[1] 正负取决于n的奇偶, 反正一直一负过来就对了
然后就用上大数神器 java 就ok了. C要靠递推算的, 打表分分钟给跪.. 算C的基本大点的 都是可以递推的, 不用重新算的
C(0,n-1) 要特判一下 得1
C(0,n-1)*n-1/1=C(1,n-1)
C(1,n-1) *n-2/ 2= C(2,n-1)
C(2,n-1) *n-3/ 3 = C(3,n-1)
for(i=n;i >= 1;i--)循环下 如果i!=n
C(i+1,n-1)* i / (n-i)=C(i,n-1)
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Scanner;
import java.util.Arrays;
import java.io.*;
public class Main
{
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
BigInteger arr[]=new BigInteger[3010];
BigInteger sum = null,ans= null;
int t,n,j,i,flag,a,b,k;
t=scanner.nextInt();
for(j=0;j<t;j++)
{
n=scanner.nextInt();
for(i=1;i<=n;i++)
{
arr[i]=scanner.nextBigInteger();
}
flag=1;
sum=BigInteger.valueOf(0);
ans=BigInteger.valueOf(1);
for(i=n;i>=1;i--)
{
if(n-i!=0)
ans=ans.divide(BigInteger.valueOf(n-i));
if(n-i==0||i==0)
ans=BigInteger.valueOf(1);
if(flag==1)//用于正负交换
{
arr[i]=arr[i].multiply(ans);
sum=sum.add(arr[i]);
}
if(flag==2)
{
arr[i]=arr[i].multiply(ans);
sum=sum.subtract(arr[i]);
}
if(flag==1)
flag=2;
else if(flag==2)
flag=1;
}
System.out.println(sum);
}
}
}