UVA 1546 - Complete the sequence!(差分法)
2014-07-22 09:17
225 查看
UVA 1546 - Complete the sequence!
题目链接题意:给定多项式前s项,求出后c项,要求尽量小
思路:利用差分法,对原序列求s - 1次差分,就可以发现规律,然后对于每多一项,就逆推回去即可
代码:
#include <stdio.h>
#include <string.h>
const int N = 205;
int t, s, c, a
;
int main() {
scanf("%d", &t);
while (t--) {
scanf("%d%d", &s, &c);
memset(a, 0, sizeof(a));
for (int i = 0; i < s; i++)
scanf("%d", &a[0][i]);
for (int i = 1; i < s; i++)
for (int j = 0; j < s - i; j++)
a[i][j] = a[i - 1][j + 1] - a[i - 1][j];
for (int i = 0; i < c; i++) {
for (int j = s - 1; j >= 0; j--)
a[j][s - j + i] = a[j + 1][s - j - 1 + i] + a[j][s - j - 1 + i];
printf("%d%c", a[0][s + i], (i == c - 1 ? '\n' : ' '));
}
}
return 0;
}
相关文章推荐
- UVA 1546 - Complete the sequence!(差分法)
- uva 1546 - Complete the sequence!(牛顿插值法)
- 【UVA】【第0章】694 - The Collatz Sequence
- UVA 694 - The Collatz Sequence
- UVA - 694 - The Collatz Sequence
- hdu 1121 差分计算 Complete the Sequence
- uva694 The Collatz Sequence
- Complete the Sequence[HDU1121]
- UVa694 - The Collatz Sequence(模拟)
- UVA 10479 The Hendrie Sequence
- UVA 694 The Collatz Sequence
- UVa 694 The Collatz Sequence
- HDU 1121 Complete the Sequence 差分
- uva694 The Collatz Sequence
- 【HDU】 1121 Complete the Sequence
- UVa 694 The Collatz Sequence(序列)
- uva 10479——The Hendrie Sequence
- 杭电ACM HDU 1121 Complete the Sequence
- UVa 694 The Collatz Sequence (数论)
- HDOJ 1121 Complete the Sequence