Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=1041
Test instructions: The computer has the number 1, to expand the operation, if the encounter 1 becomes "01", if you encounter 0, becomes "10", after a transformation called "01", two Times "1001", three times "01101001",
The number of the 01 sequences that are obtained by the N-Times transformation is 0.
Idea: first hit the table to get regular 1,1,3,5,11,21,43 ...
Find the rules to find
1*2+1=3;
1*2+3=5;
3*2+5=11;
5*2+11=21;
...... ;
After that is the sum of things, because the result is too big, do it with a large number.
#include <iostream>#include<cstdio>#include<string>using namespacestd;stringstr[1010];stringAddstringS1,stringS2) { if(S1.length () <s2.length ()) { stringtmp=S1; S1=S2; S2=tmp; } intL1=s1.length (), l2=s2.length (), i,j; for(i=l1-1, j=l2-1; i>=0; I--, j--) {S1[i]=Char(S1[i]+ (j>=0? s2[j]-'0':0)); if(s1[i]-'0'>=Ten) {S1[i]=Char((s1[i]-'0')%Ten+'0'); if(i) s1[i-1]++; Elses1="1"+S1; } } returnS1;}intMainvoid) {str[1]="0", str[2]="1", str[3]="1", str[4]="3", str[5]="5", str[6]=" One"; for(intI=7; i<=1005; i++) {Str[i]=add (Add (str[i-2],str[i-2]), str[i-1]); } intN; while(~SCANF ("%d",&N)) {cout<<str[n]<<Endl; } return 0;}
hdu-1041 (large number of templates)