题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=1121
Complete the Sequence
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 451 Accepted Submission(s): 283
ACM programmers have noticed that some of the quizzes can be solved by describing the sequence by polynomials. For example, the sequence 1, 2, 3, 4, 5 can be easily understood as a trivial polynomial. The next number is 6. But even more complex sequences, like 1, 2, 4, 7, 11, can be described by a polynomial. In this case, 1/2.n^2-1/2.n+1 can be used. Note that even if the members of the sequence are integers, polynomial coefficients may be any real numbers.
Polynomial is an expression in the following form:
P(n) = aD.n^D+aD-1.n^D-1+...+a1.n+a0
The second line of each test case contains S integer numbers X1, X2, ... XS separated by a space. These numbers form the given sequence. The sequence can always be described by a polynomial P(n) such that for every i, Xi = P(i). Among these polynomials, we can find the polynomial Pmin with the lowest possible degree. This polynomial should be used for completing the sequence.
It is guaranteed that the results Pmin(S+i) will be non-negative and will fit into the standard integer type.

#include<iostream>
#include<cstdio>
#include<cstring> using namespace std; const int maxn = ; int s, c;
int f[maxn][maxn]; void init() {
memset(f, , sizeof(f));
} int main() {
int tc;
scanf("%d", &tc);
while (tc--) {
init();
scanf("%d%d", &s, &c);
for (int i = ; i < s; i++) scanf("%d", &f[][i]);
for (int i = ; i <= s - ; i++) {
for (int j = ; j < s - i; j++) {
f[i][j] = f[i - ][j + ] - f[i - ][j];
}
}
for (int i = ; i <= c; i++) f[s - ][i] = f[s - ][i - ];
for (int i = s - ; i >= ; i--) {
for (int j = s - i; j < s + c - i; j++) {
f[i][j] = f[i][j - ] + f[i + ][j - ];
}
}
printf("%d", f[][s]);
for (int i = s + ; i < s + c; i++) printf(" %d", f[][i]);
printf("\n");
}
return ;
}