您的位置:首页 > 产品设计 > UI/UE

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: