poj 2680 Computer Transformation (dp+高精度)
来源:互联网 发布:燕十八mysql教程 网盘 编辑:程序博客网 时间:2024/06/16 14:33
Computer Transformation
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 4653 Accepted: 1765
Description
A sequence consisting of one digit, the number 1 is initially written into a computer. At each successive time step, the computer simultaneously tranforms each digit 0 into the sequence 1 0 and each digit 1 into the sequence 0 1. So, after the first time step, the sequence 0 1 is obtained; after the second, the sequence 1 0 0 1, after the third, the sequence 0 1 1 0 1 0 0 1 and so on.
How many pairs of consequitive zeroes will appear in the sequence after n steps?
How many pairs of consequitive zeroes will appear in the sequence after n steps?
Input
Every input line contains one natural number n (0 < n <= 1000).
Output
For each input n print the number of consequitive zeroes pairs that will appear in the sequence after n steps.
Sample Input
23
Sample Output
11
Source
Southeastern Europe 2005
[Submit] [Go Back] [Status] [Discuss]
题解: dp+高精度
找规律发现f[i]=f[i-1]+f[i-2]*2
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#define N 1003#define LL long longusing namespace std;int f[N][N],n,c[N];void calc(int x,int y,int z){for (int i=0;i<=f[y][0];i++) f[x][i]=f[y][i];memset(c,0,sizeof(c));for (int i=1;i<=f[z][0];i++) c[i]=f[z][i]*2;int t=f[z][0];for (int i=1;i<=t;i++) c[i+1]+=c[i]/10,c[i]%=10;while (c[t+1]) {t++;c[t+1]+=c[t]/10;c[t]%=10;}c[0]=t;for (int i=1;i<=max(t,f[x][0]);i++) f[x][i]+=c[i]; f[x][0]=max(t,f[x][0]); for (int i=1;i<=f[x][0];i++) f[x][i+1]+=f[x][i]/10,f[x][i]%=10; while (f[x][f[x][0]+1]){ f[x][0]++; f[x][f[x][0]+1]+=f[x][f[x][0]]/10; f[x][f[x][0]]%=10;}}int main(){ f[1][1]=0; f[1][0]=1; f[2][1]=1; f[2][0]=1; for (int i=3;i<=1000;i++) { calc(i,i-1,i-2); } while (scanf("%d",&n)!=EOF){ for (int i=f[n][0];i>=1;i--) printf("%d",f[n][i]); printf("\n"); }}
0 0
- poj 2680 Computer Transformation (dp+高精度)
- POJ Computer Transformation 递推 + 高精度
- POJ 2680 / ZOJ 2584 : Computer Transformation - 打表+找规律+高精度 / java大数
- POJ-2680(简单递推)(Computer Transformation )
- HDU 1041 Computer Transformation 【找规律+高精度】
- HDU 1041 Computer Transformation 数学DP题解
- HDU1041 Computer Transformation(java)
- Computer Transformation
- POJ 3181 Dollar Dayz (DP+高精度)
- poj 3181 dp+高精度(数字拆分)
- UVa 1647 - Computer Transformation(大数)
- hdu 1041 Computer Transformation(规律+大数)
- Computer Transformation(ZJU_2584)
- HDOJ 1041 Computer Transformation
- HDU 1041 Computer Transformation
- HDU-1041-Computer Transformation
- 1041:Computer Transformation
- hdu1041-Computer Transformation
- 动态在代码中设置权重
- C++隐藏代码,被隐藏的代码不被执行
- 值类型和引用类型
- 图片处理方法总结
- 服务器重装
- poj 2680 Computer Transformation (dp+高精度)
- jq获取复选框的值(全选,反选等)
- Thinkphp5 数据分页显示
- 测试sizeof()
- Mybatis 高级结果映射 ResultMap Association Collection
- MFC控件属性修改笔记
- Binder service入门—Framework binder service
- 接口
- Hash表(2)——开放地址法