• <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

            2nd JOJ Cup Online VContest Problem

            We all know that bunny is fond of carrots. One cloudy day, he was told that there would be a violenting flood coming soon to destroy the forests. He was scared and after not thinking too much he told himself that he had to escape. He suddenly recalled that there was a temple on the top of the hill and he might shelter there until the flood's past. But unfortunately there was no food for him on the top of the hill, so he had to take his carrots away along with himself. Then he moved to the foot of the hill and stopped. There was only one way for him to get the top of the hill, that is, a long staircase. Given the number of the steps of the staircase, he asked himself:"how many different ways of strides are there for him to get the top of the hill?". Of course, because of his height, he could only stride a limited range of steps. He was smart so much so that he got the answer quickly. Do you know how he did it?

            Input Specification

            The input consists of several test cases, each of which occupies a line containing M(1<=M<=40) and N(1<=N<=10), where M indicates the number of the steps of the staircase and N indicates the maximal number of steps the bunny can stride once.

            Output Specification

            Each test case should correspond to a line in the output. Your program should print an integer which is the answer.

            Sample Input

            4 2
            5 4

            Sample Output

            5
            15


            題意是一只兔子要到距離為M(單位為1)的地方,它每步最多走N,問有多少種方法。輸入M  N 輸出r[m][n];


            解析:設為r[i][j],表示距離總共i且每次最多走j的方法數(可以沒有走出那大小為j的那步,只是允許走那步而已)。

            根據最后那一步可能走的長度,r[i-2][j]表示最后那步距離為2.r[i-j][j]表示最后那步距離為j.
            建立遞推關系r[i][j]=r[i-1][j]+r[i-2][j]+r[i-3][j]+r[i-j][j];
            //本人覺得這里特別難想,想到了也覺得無法建立遞推關系呀,j不是一直不變嗎?
            神奇的地方在于可以令r[0][j]=r[1][j]=1;當然還有r[i][1]=1
            -----------預處理----
            for(j=0;j<n;j++)

                   {

                          r[0][j]=1;

                          r[1][j]=1;

                   }

                   for(i=0;i<n;i++)

                          r[i][1]=1;


            ---dp----------
             for(i=2;i<m;i++)
                for(j=2;j<n;j++)
                {
                 if(i<j)
                    r[i][j]=r[i][i]; //這點非常重要
                 else 
                   for(k=1;k<=j;k++)
                    {
               r[i][j]+=r[i-k][j];
                    }
                }
            ------------
            r[1][1]=1
            r[2][1]=1
            r[2][2]=r[2][1]+r[2][2]=2;
            r[3][1]=1;
            r[3][2]=r[2][2]+r[1][2]=3;
            r[3][3]=r[0][3]+r[1][3]+r[2][3]=4;

            posted on 2009-07-20 17:19 luis 閱讀(555) 評論(0)  編輯 收藏 引用 所屬分類: 動態規劃
            <2009年7月>
            2829301234
            567891011
            12131415161718
            19202122232425
            2627282930311
            2345678

            常用鏈接

            留言簿(3)

            隨筆分類

            隨筆檔案

            文章分類

            文章檔案

            友情鏈接

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            免费一级欧美大片久久网| 久久精品无码一区二区三区免费| 久久久久国产精品嫩草影院| 日本高清无卡码一区二区久久| 亚洲国产天堂久久综合| 亚洲精品乱码久久久久久中文字幕| 久久精品国产半推半就| 久久午夜夜伦鲁鲁片免费无码影视 | 成人久久免费网站| 狠狠色丁香婷综合久久| 亚洲欧美成人久久综合中文网| 久久99热狠狠色精品一区| 人妻无码久久精品| 亚洲国产精品久久66| 蜜臀av性久久久久蜜臀aⅴ| 久久精品亚洲男人的天堂| 7777久久亚洲中文字幕| 亚洲精品美女久久久久99| 伊人久久精品影院| 亚洲国产天堂久久综合| 久久se这里只有精品| 麻豆精品久久精品色综合| 久久夜色精品国产欧美乱| 午夜精品久久久久久影视777| 九九99精品久久久久久| 国产V综合V亚洲欧美久久| 九九精品99久久久香蕉| 久久精品中文字幕无码绿巨人| 久久国语露脸国产精品电影| 久久综合色区| 久久99国产精品久久99小说| 一个色综合久久| 尹人香蕉久久99天天拍| 国产激情久久久久久熟女老人| 一本色道久久综合| 亚洲乱码精品久久久久..| 亚洲国产另类久久久精品| 狠狠色噜噜色狠狠狠综合久久| 久久久久久久波多野结衣高潮| 久久精品国产亚洲AV不卡| 亚洲AV无一区二区三区久久|