斐波那契數列,大數據

Description

You 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 many different results. For example, given 1111 , you can get 1111, 121, 112,211,22. Now, your work is to find the total number of result you can get. 

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. 

Output

The output contain n lines, each line output the number of result you can get . 

Sample Input

3
1
11
11111

Sample Output

1
2

8

#include <stdio.h> #include <string.h> #include<ctype.h> #define M 220 int a[M][220]; char str[M]; int main() {     int i, j, n, temp, T;     scanf("%d",&T);     memset(a, 0, sizeof(a));     a[1][0] = 1;     a[2][0] = 2;     for(i = 3; i < M; i ++)     {         for(j = 0; j < 220; j ++)             a[i][j] = a[i-1][j]+a[i-2][j];         for(j = 0; j < 219; j ++)         {             if(a[i][j] >= 10000)             {                 temp = a[i][j]/10000;                 a[i][j] %= 10000;                 a[i][j+1] += temp;             }         }     }     while( T--)     {         scanf("%s", str);         n=strlen(str);          i = 219;         while(a[n][i] == 0)          i--;         printf("%d", a[n][i]);         i--;         while(i >= 0 )         {             printf("%04d", a[n][i]);             i--;         }         puts("");     }     return 0; }

發佈了78 篇原創文章 · 獲贊 9 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章