• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            posts - 195,  comments - 30,  trackbacks - 0

            One curious child has a set of N little bricks. From these bricks he builds different staircases. Staircase consists of steps of different sizes in a strictly descending order. It is not allowed for staircase to have steps equal sizes. Every staircase consists of at least two steps and each step contains at least one brick. Picture gives examples of staircase for N=11 and N=5:

            Your task is to write a program that reads from input numbers N and writes to output numbers Q - amount of different staircases that can be built from exactly N bricks.


            Input

            Numbers N, one on each line. You can assume N is between 3 and 500, both inclusive. A number 0 indicates the end of input.

             

             


            Output

            Numbers Q, one on each line.

             


            Sample Input

            3
            5
            0
            

            Sample Output

            1
            2
            
            方法1,動態規劃

            #include<iostream>
            #include<cstdlib>
            using namespace std;
              int main()
              {
              freopen("s.txt","r",stdin);
              freopen("key.txt","w",stdout);
              double f[501][501]={0};
              double s;
              int i,j,k,n;
              for(i=3;i<=500;i++)
              for(j=1;j<=(i-1)/2;j++)
                f[i][j]=1;
              for(i=3;i<=500;i++)
                for(j=1;j<=(i-1)/2;j++)
                {
             for(k=j+1;k<=(i-j-1)/2;k++)
               f[i][j]=f[i-j][k]; 
             }
                while(scanf("%d",&n),n) {
                    s=0;
                    for(i=1;i<=(n-1)/2;i++) s+=f[n][i]; //f[n]=f[n][1]+f[n][2]+-----+f[n][floor((i-1)/2)]
                    printf("%.0f\n",s);
                }
              //system("PAUSE");
              return   0;
              }
            更妙的方法:生成函數法
            計算(1+x)(1+x^2)(1+x^3)-----,x^n的系數即為所求
            int i,j;
            double ans[510]={1,1};//已經把ans[1]和ans[0]賦為1了,其余為0
             for(i=2;i<=500;i++) {  
                    for(j=500;j>=0;j--) { 
                        if(i+j<=500) ans[i+j]+=ans[j];
                    } 
                } 

            先計算(1+x)(1+x^2)
            再計算(1+x)(1+x^2)   *(1+x^3)
            posted on 2009-06-27 10:44 luis 閱讀(422) 評論(0)  編輯 收藏 引用 所屬分類: 組合數學動態規劃給我啟發題
            <2009年7月>
            2829301234
            567891011
            12131415161718
            19202122232425
            2627282930311
            2345678

            常用鏈接

            留言簿(3)

            隨筆分類

            隨筆檔案

            文章分類

            文章檔案

            友情鏈接

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            91久久精品91久久性色| 亚洲精品美女久久久久99小说 | 久久国语露脸国产精品电影| 精品久久久久久无码不卡| 伊人久久大香线蕉亚洲五月天| 精品国际久久久久999波多野| 久久综合久久综合久久| 久久人妻AV中文字幕| 国产精品久久毛片完整版| 天天影视色香欲综合久久| 久久婷婷五月综合色奶水99啪| 国产福利电影一区二区三区,免费久久久久久久精 | 午夜人妻久久久久久久久| 91精品国产综合久久四虎久久无码一级| 欧美亚洲日本久久精品| 99久久99久久久精品齐齐| 亚洲国产成人久久一区WWW| 国产精品久久网| 人妻无码αv中文字幕久久琪琪布| 91精品国产综合久久香蕉| 精品久久人妻av中文字幕| 欧美色综合久久久久久| 大蕉久久伊人中文字幕| 久久综合九色综合网站| 久久WWW免费人成一看片| 久久中文字幕视频、最近更新| 久久免费高清视频| 精品人妻久久久久久888| 色天使久久综合网天天| 亚洲国产成人久久综合区| 精品国产乱码久久久久久浪潮| 久久久精品国产sm调教网站| 欧美熟妇另类久久久久久不卡| 区久久AAA片69亚洲| 国产精品久久久久久久久久影院| 亚洲精品乱码久久久久久蜜桃| 办公室久久精品| 青青热久久国产久精品| 欧美精品丝袜久久久中文字幕| 亚洲精品99久久久久中文字幕 | 青青青国产精品国产精品久久久久|