1. 程式人生 > >hdu杭電1865 1sting

hdu杭電1865 1sting

Problem 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
//做完fibonacci和大菲波數就能懂了 

#include<stdio.h>
#include<string.h>
char s[210];
int num[210][1010];
int len;
int main()
{
    int n;
    int i,j;
    memset(num,0,sizeof(num));
    num[1][0]=1;
    num[2][0]=2;
    //int k,l;
    //l=0;
    for(i=3;i<210;i++)
    {
        //k=0;
        for(j=0;j<1000;j++)
        {
            //l=k+num[i-1][j]+num[i-2][j];
            //num[i][j]=l%10;
            //k=l/10;
            num[i][j]+=num[i-1][j]+num[i-2][j];//'+='把我坑慘了 ,我寫成=
            if(num[i][j]>=10)
            {
            	num[i][j]-=10;
            	num[i][j+1]+=1;
            }
        }           
    }
    scanf("%d",&n);
    getchar();
    while(n--)
    {    
        scanf("%s",s);
        len=strlen(s);     
		for(i=1000-1;i>0&&num[len][i]==0;--i)//清零 
		;
		  
        for(;i>=0;i--)
           printf("%d",num[len][i]);
        printf("\n");
    }
    return 0;
}


相關推薦

hdu1865 1sting

Problem 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 g

1865 1sting

1sting Time Limit : 5000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submission(s) :   Accepted Submission(s) :

HDU Today HDU2112【Dijkstra || SPFA】

esc 眼神 inpu mark 數據 auto 結束 性格 以及 http://acm.hdu.edu.cn/showproblem.php?pid=2112 Problem Description 經過錦囊相助,海東集團最終度過了危機,從此。HDU的發展就

Advanced Fruits HDU1503【LCS的保存】

style pro cte rac data- sequence return arch its Problem Description The company "21st Century Fruits" has specialized

一個人的旅行 HDU2066【dijkstra算法 || SPFA】

個數 strong -s stdio.h rip include tom trac 第一次 http://acm.hdu.edu.cn/showproblem.php?pid=2066 Problem Description 盡管草兒是個路癡(就是在杭電待了一

Choose the best route HDU2680【dijkstra算法 || SPFA】

ace suppose include ria fine main from def wan http://acm.hdu.edu.cn/showproblem.php?pid=2680 Problem Description One day , Kiki wan

HDU2111 Saving HDU【揹包問題】

話說上回講到海東集團面臨內外交困,公司的元老也只剩下XHD夫婦二人了。顯然,作為多年拼搏的商人,XHD不會坐以待斃的。   一天,當他正在苦思冥想解困良策的時候,突然想到了自己的傳家寶,那是公司成立的時候,父親作為賀禮送來的一個錦囊,徐父當時交代,不到萬不得已的時候,不要開啟它。“現在不正是最需要的時候嗎?”

HDU acm-2093-考試排名

/************************************************************************ 這題廢了一番功夫。。 首先題目沒給出人數,乍一看懵了。參考了網上的程式碼,用 while(scanf("%s",name)!

HDU----3572--Task Schedule--最大流

Task Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5031    Accepted S

Tri Tiling HDU 1143 【規律題】

Problem Description In how many ways can you tile a 3xn rectangle with 2x1 dominoes? Here is a sample tiling of a 3x12 rectangle. Inp

『ACM C++』HDUOJ | 1415 - Jugs (灌水定理引申)

size 任務 手寫 posit integer another 說我 清空 www.   今天總算開學了,當了班長就是麻煩,明明自己沒買書卻要帶著一波人去領書,那能怎麽辦呢,只能說我善人心腸哈哈哈,不過我腦子裏突然浮起一個念頭,大二還要不要繼續當這個班委呢,既然已經體

-oj】-1865-1sting(大數斐波那契數列)

1sting Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5021    Accepted Submiss

HDU 4920(多校訓練#5 1010 題) Matrix multiplication(不知道該掛個什麽帽子。。。)

預處理 ica ref 循環 ring sca esp 題解 code 題目地址:HDU 4920 對這個題簡直無語到極點。。。竟然O(n^3)的復雜度能過。。。。方法有三。。 1:進行輸入優化和輸出優化。。(前提是你的輸入優化不能太搓。。。) 2:利用緩存優化。。詳情

HDU 4968(多校#9 1009題)Improving the GPA (瞎搞)

popu 推斷 imp 暴力枚舉 pop ++ pos nan sin 題目地址:HDU 4968 這題的做法是全部學科的學分情況枚舉,然後推斷在這樣的情況下是否會符合平均分。直接暴力枚舉就可以。 代碼例如以下: #include <cstring> #i

hdu)2053 Switch Game 水題

center ++ class chang names top weight ext == Switch Game Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (J

hdu)1181 變形課

pac ems out 成了 problem mar acc 順序 silver 變形課 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)

2018多校第六場(2018 Multi-University Training Contest 6) 1012.Pinball(HDU 6373) -簡單的計算幾何+物理受力分析

info 簡單的 垂直 -- vector 分析 code space cti 6373.Pinball 物理受力分析題目。 畫的有點醜,通過受力分析,先求出θ角,為arctan(b/a),就是atan(b/a),然後將重力加速度分解為垂直斜面的和平行斜面的,垂直

ACM hdu 2079 選課時間 (模板)

Problem Description 又到了選課的時間了,xhd看著選課表發呆,為了想讓下一學期好過點,他想知道學n個學分共有多少組合。你來幫幫他吧。(xhd認為一樣學分的課沒區別) Input輸入資料的第一行是一個數據T,表示有T組資料。每組資料的第一行是兩個整數n(1 <= n <

2018多校第一場1011(hdu 6308)

題解:這題主要會超時,不能用string。可以使用sscanf提取字串。 #include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<queue

2018多校第一場1003(hdu 6300)

題解:畫個圖發現只要按橫座標排序,每次取三個點就永遠不會相交 #include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<queue> #