1 sting
Time Limit: 5000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 3442 accepted submission (s): 1332
Problem descriptionyou will be given a string which only contains '1'; you can merge two adjacent '1' to be '2', or leave the '1' there. surly, you may get your different results. for example, given 1111, you can get 1111,121,112,211, 22. now, your work is to find the total number of results you can get.
Inputthe first line is a number N refers to the number of test cases. then n lines follows, each line has a string made up of '1 '. the maximum length of the sequence is 200.
Outputthe output contain N lines, each line output the number of results you can get.
Sample Input
311111111
Sample output
128
You will get a string containing only "1". You can merge two adjacent '1' into '2 '. Of course, you may get many different results. For example, you can get 1111,1111, 121,112211, 22. Now, your job is to find the maximum number of types of results for this string.
Input
The first line is a number N refers to the number of test cases. then n lines follows, each line has a string made up of '1 '. the maximum length of the sequence is 200.
The first line is a number N, which refers to the number of test cases. Then there are less than n lines, each line has a string consisting of 1. The maximum length of a sequence is 200.
Error cause
I first found out that this is a Fibonacci series. I also thought of using int64 bits, but the range is still not enough. Well, sorry, I didn't expect it to be combined with the addition or subtraction of large numbers. The addition or subtraction of large numbers is not easy to grasp. After using if, you will habitually forget the else situation.
Code
#include<stdio.h>#include<string.h>char s[230];int num[230][1000];int len[1000];//int len[100]; 数组开小了。 int main(){//这道题是斐波那契数列和大数加减法的结合 int n;int i,j,k,l,m;memset(num,0,sizeof(num));//二维数组也可以这样初始化。 num[1][0]=1;num[2][0]=2;len[1]=len[2]=1;l=0;for(i=3;i<210;i++){k=0;for(j=0;j<=len[i-1];j++){l=k+num[i-1][j]+num[i-2][j];num[i][j]=l%10;k=l/10;}//需要定义l,k两个变量。 if(num[i][len[i-1]]!=0) len[i]=len[i-1]+1;else//else老是忘记,这儿出错了 len[i]=len[i-1];}//因为200位呢,需要用大数。 scanf("%d",&n);getchar();while(n--){scanf("%s",s);m=strlen(s);for(i=len[m]-1;i>=0;i--) printf("%d",num[m][i]);printf("\n");}return 0;}
1410121949-hd-1sting