HDU 1041 Computer Transformation 大数递推
2014-07-05 22:14
316 查看
Computer Transformation
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5787 Accepted Submission(s): 2090
Problem 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?
Input
Every input line contains one natural number n (0 < n ≤1000).
Output
For each input n print the number of consecutive zeroes pairs that will appear in the sequence after n steps.
Sample Input
Sample Output
[code]
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5787 Accepted Submission(s): 2090
Problem 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?
Input
Every input line contains one natural number n (0 < n ≤1000).
Output
For each input n print the number of consecutive zeroes pairs that will appear in the sequence after n steps.
Sample Input
2 3
Sample Output
1 1
[code]
/* 要学会分析题目啊。。。。。 00的产生必然由n-1组的01产生,即00的个数等于n-1组01的个数。 n-1组01的产生有两个来源。 1).由n-2组的1 2).由n-2组的00变幻1010, 其中一个00只能产生一个01.这个就是要求的n-2连续的个数 可以推出第n组00的个数dp =dp[n-2]+第n-2组1的个数(2^((n-2)-1)); 发现还要用大数 */ #include<iostream> #include<cstring> using namespace std; int dp[1002][500];//因为两个长度 比较麻烦 直接500 不记长度 int p[500]; int main(){ int n,i,j,z,t; memset(p,0,sizeof(p)); memset(dp,0,sizeof(dp)); dp[1][1]=0; dp[2][1]=1; dp[3][1]=1; p[1]=1; for(i=4;i<1001;i++) { for(j=1;j<500;j++)//处理2的多次方 p[j]=p[j]*2; z=0; for(j=1;j<500;j++) { t=p[j]+z; z=t/10; p[j]=t%10; } for(j=1;j<500;j++)//处理递推方程 dp[i][j]=dp[i-2][j]+p[j]; z=0; for(j=1;j<500;j++) { t=dp[i][j]+z; z=t/10; dp[i][j]=t%10; } } while(cin>>n) { i=499; while(dp [i]==0) i--; for(;i>=1;i--) printf("%d",dp [i]); if(n!=1) printf("\n"); else printf("0\n"); } return 0; }
相关文章推荐
- hdu 1041(递推,大数)
- HDU 1041 递推 大数
- HDU 1041 递推 + 大数模板
- hdu 1041 Computer Transformation(大数递推)
- HDU 1316 How Many Fibs?(递推,大数相加)
- HDU-1041-Computer Transformation(规律题 && 大数题)
- hdu 1041(规律+打表+java大数)
- hdu 1041 Computer Transformation(递推+大整数模板*)
- HDU-1041大数运算+递归
- hdu 1041大数问题
- hdu 1133 Buy the Ticket (大数+递推)
- hdu 1041(Computer Transformation)(找规律,二维数组大数)
- hdu_1041(Computer Transformation) 大数加法模板+找规律
- hdu 1041 打表:递推+大数 模板
- HDU-3723 Delta Wave(卡特兰数+大数递推)
- HDU-1041-Computer Transformation,大数递推,水过~~
- HDU 1297 Children’s Queue【大数加法 + 递推】
- hdu 1297 Children’s Queue 递推 大数
- hdu 1041 Computer Transformation(规律+大数)
- hdu1041 Computer Transformation 大数找规律