Series 1
Note:
It is not easy to translate the question. It is not difficult to understand English.
Problem description Let A be an integral series {A1, A2,..., }.
The zero-order series of A is a itself.
The first-order series of A is {b1, b2,..., Bn-1}, where bi = ai + 1-ai.
The ith-order series of A is the first-order series of its (I-1) Th-order series (2 <= I <= n-1 ).
Obviusly, 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.
The second line consists of N integers, describing A1, A2,..., An. (0 <= AI <= 105)
Output for each test case, output the required integer in a line.
Sample input231 2 341 5 7 2
Sample Output0-5 idea: Match Nan Jie soon launched to the formula, want to Yang Hui triangle preprocessing out, and then found that biginteger size burst memory .... I am speechless and want to optimize it on the basis of violence, and then I will never die... The competition is not over yet. After the game, I learned that the Yang Hui triangle can be launched directly using the combination formula... The number of M in row N in the Yang Hui triangle is the number of composite C [n-1] [M-1]. The application C [N] [m] = C [N] [M-1] * (N-m + 1)/m enables express delivery to launch the nth line number, this not only avoids the memory burst during table hitting, but also saves a lot of time for brute force ..... Still too young...
1 import java.io.*; 2 import java.math.*; 3 import java.util.*; 4 public class Main { 5 6 static BigInteger coe[][] = new BigInteger [3010][3010]; 7 public static void main(String[] args) throws IOException{ 8 Scanner cin = new Scanner(System.in); 9 BigInteger []a = new BigInteger[3010]; 10 BigInteger []c = new BigInteger[3010]; 11 int T;12 T = cin.nextInt();13 while(T-- > 0){14 int n;15 n = cin.nextInt();16 for(int i = 1; i <= n; ++i){17 a[i] = cin.nextBigInteger();18 }19 BigInteger ans = BigInteger.ZERO;20 c[0] = BigInteger.ONE;21 ans = ans.add(c[0].multiply(a[n]));22 int t = -1;23 for(int i = 1; i < n; ++i){24 BigInteger t1 = BigInteger.valueOf(n).subtract(BigInteger.valueOf(i)); 25 BigInteger t2 = BigInteger.valueOf(i);26 c[i] = c[i-1].multiply(t1).divide(t2); 27 ans = ans.add(c[i].multiply(a[n-i]).multiply(BigInteger.valueOf(t)));28 t *= -1; 29 }30 System.out.println(ans);31 }32 33 }34 }
HDU 4927