【HDU】 1121 Complete the Sequence
来源:互联网 发布:win7重置网络 编辑:程序博客网 时间:2024/05/18 06:18
Complete the Sequence
题目链接
- Complete the Sequence
题目大意
这题题意挺好懂的,就是给你一列数,现在然你找规律找到后面S位是什么。
题解
首先这题是用差分求解。
关于这题为什么要差分,我不知道….看了好多东西还是不懂…我这里就直接写解法吧。
我们对前面n个数,求其差分,从1阶差分一直求到n-1阶差分,可以想到如果在第k阶差分全部相同的话,P的阶就是k(因为后面更高阶的差分全部为零了,即使求和也不会改变阶数),因为我们求出n-1阶差分后就只剩下一个数了,于是我们在后面构造S个跟该数相同的数然后倒推回去,就得到了解。
我的问题主要在于,如果我们求出n-1阶差分后最后一个数仍然不等于0的话,即使这列数满足某个多项式它也应该是n阶的,我们应该求不出来或者是求出它的某一个n-1阶近似才对,可是我们这样写却AC了….
代码
#include <iostream>#include <cstring>#include <cstring>#include <cstdlib>#include <cstdio>using namespace std;int n,s,d[110][110],T;int main(){ scanf("%d",&T); while(T--) { memset(d,0,sizeof(d)); scanf("%d%d",&n,&s); for (int i=0;i<n;i++) scanf("%d",&d[0][i]); for (int i=1;i<=n-1;i++) for (int j=i;j<n;j++) d[i][j]=d[i-1][j]-d[i-1][j-1]; for (int j=n;j<n+s;j++) d[n-1][j]=d[n-1][n-1]; for (int i=n-2;i>=0;i--) for (int j=n;j<n+s;j++) d[i][j]=d[i][j-1]+d[i+1][j]; for (int j=n;j<n+s-1;j++) printf("%d ",d[0][j]); printf("%d\n",d[0][n+s-1]); } return 0;}
0 0
- HDU 1121 Complete the Sequence
- 【HDU】 1121 Complete the Sequence
- HDU 1121 Complete the Sequence 数学题
- hdu 1121 Complete the Sequence(插值差分)
- hdu 1121 Complete the Sequence(DP多项式差分)
- 杭电ACM HDU 1121 Complete the Sequence
- hdu 1121 差分计算 Complete the Sequence
- hdu1121 Complete the Sequence
- HDU 1211 Complete the Sequence(差分方法)
- UVA 1546 - Complete the sequence!(差分法)
- uva 1546 - Complete the sequence!(牛顿插值法)
- HDU1121——Complete the Sequence
- 数论+差分 hdu1121 Complete the Sequence
- POJ - Complete the Sequence! - 生成完整序列数
- hdu-5063 Operation the Sequence
- HDU - 5036 Operation the Sequence
- Hdu 5063 Operation the Sequence
- Hdu 5063 Operation the Sequence
- C++走向远洋——55(项目一3、分数类的重载、>><<的重载)
- C语言存储空间管理和链表杂记
- Android开发实现高德地图定位详解
- Accepting connections from both IPv6 and IPv4 clients
- 使用Netty进行文件传输
- 【HDU】 1121 Complete the Sequence
- 开源框架
- github客户端的使用(Windows系统)
- SQL语句插入变量
- Android 消息循环源码剖析
- poj1125(最短路floyd算法)
- 程序是怎样跑起来的-第10章 通过汇编语言了解程序的实际构成
- |Tyvj|BFS|P1030 乳草的入侵
- c++ 拷贝构造函数