• <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 閱讀(426) 評論(0)  編輯 收藏 引用 所屬分類: 組合數學動態規劃給我啟發題
            <2025年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            常用鏈接

            留言簿(3)

            隨筆分類

            隨筆檔案

            文章分類

            文章檔案

            友情鏈接

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            亚洲国产成人久久综合碰| 少妇久久久久久被弄高潮| 国产免费久久精品99久久| 日本国产精品久久| 久久综合狠狠综合久久| 国内精品久久久久久不卡影院| 色狠狠久久综合网| 波多野结衣中文字幕久久| 久久精品综合一区二区三区| 无码伊人66久久大杳蕉网站谷歌 | 999久久久免费国产精品播放| 久久99热这里只频精品6| 91精品国产乱码久久久久久| 亚洲精品国产第一综合99久久| 久久综合中文字幕| 久久精品国产亚洲AV香蕉| 亚洲精品无码久久毛片| 久久av免费天堂小草播放| 日本福利片国产午夜久久| 色综合久久久久无码专区| 国内精品久久久久影院亚洲| 国产成人香蕉久久久久| 国产成人久久AV免费| 久久久久久久97| 无码伊人66久久大杳蕉网站谷歌| 午夜肉伦伦影院久久精品免费看国产一区二区三区 | 久久99中文字幕久久| 亚洲中文字幕无码久久综合网 | 亚洲AV日韩精品久久久久久| 久久99精品国产麻豆蜜芽| 久久精品国内一区二区三区| 国产偷久久久精品专区| 国产成人综合久久精品红| 久久综合伊人77777麻豆| 久久青青草原精品国产软件| 国产一区二区精品久久岳| 国内精品久久久久久麻豆| 久久93精品国产91久久综合| 久久精品国产黑森林| 亚洲欧美另类日本久久国产真实乱对白 | 久久精品极品盛宴观看|