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

            New Zealand currency consists of $100, $50, $20, $10, and $5 notes and $2, $1, 50c, 20c, 10c and 5c coins. Write a program that will determine, for any given amount, in how many ways that amount may be made up. Changing the order of listing does not increase the count. Thus 20c may be made up in 4 ways: 1 20c, 2 10c, 10c+2 5c, and 4 5c.

            Input

            Input will consist of a series of real numbers no greater than $50.00 each on a separate line. Each amount will be valid, that is will be a multiple of 5c. The file will be terminated by a line containing zero (0.00).

            Output

            Output will consist of a line for each of the amounts in the input, each line consisting of the amount of money (with two decimal places and right justified in a field of width 5), followed by the number of ways in which that amount may be made up, right justified in a field of width 12.

            Sample input

             

            0.20
            2.00
            0.00

            Sample output

             

            0.20           4
            2.00         293
            典型的動態規劃問題:
            可以先考慮只有n-1種硬幣,V1,V2,V3,---Vn-1.設湊成總值為M的方法數為result[M];
            現在又添加一種面值為Vn的硬幣。
            則咱們需要修改一些值,修改那些大于等于Vn的result[],不妨設M大于vn。
            新result[M]=原result[M]+result[M-Vn]+result[M-2*Vn]+----直到M-p*Vn<=0;(1)
            實際上如果如(2)那樣處理 從大于等于Vn的result[]開始處理的話,從小到大,設Vn=M-p*Vn;
            則result[M-p*Vn]第一個最先更新,result[M-p*Vn]+=result[M-p*Vn -Vn]   見(2)
            隨后更新result[M-(p-1)*vn],則只需直接加上result[M-p*Vn]的值,無需如(1)式那樣 累加。
            用程序表達就是
            int coin[10]={5,10,20,50,100,200,500,1000,2000,5000};
            for(i=1;i<10;i++)
             for(j=coin[i];j<=50000;j+=5)
                 result[j]+=result[j-Coin[i]];   (2) //
            -------------
            還有一個注意點,見牛人博客,http://hi.baidu.com/piaoshi111/blog/item/9a6de84a00a6e5f882025c89.html
            就是浮點數的四舍五入,
            1.5,浮點數可能表為1.4999999,所以乘以100時轉化為整型是149,應當注意。
            posted on 2009-07-19 21:45 luis 閱讀(487) 評論(0)  編輯 收藏 引用 所屬分類: 動態規劃
            <2011年4月>
            272829303112
            3456789
            10111213141516
            17181920212223
            24252627282930
            1234567

            常用鏈接

            留言簿(3)

            隨筆分類

            隨筆檔案

            文章分類

            文章檔案

            友情鏈接

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            中文无码久久精品| 少妇内射兰兰久久| 国产精品久久久天天影视香蕉| 97久久香蕉国产线看观看| 国产成人综合久久久久久| 亚洲欧美成人久久综合中文网 | 亚洲成色WWW久久网站| avtt天堂网久久精品| 欧美国产精品久久高清| 狠狠88综合久久久久综合网| 久久本道久久综合伊人| 蜜臀av性久久久久蜜臀aⅴ| 国产精品亚洲美女久久久| 欧美一区二区三区久久综合| 人妻精品久久久久中文字幕| 久久精品国产91久久麻豆自制| 亚洲日本久久久午夜精品| 国产福利电影一区二区三区久久久久成人精品综合 | 久久精品aⅴ无码中文字字幕不卡 久久精品aⅴ无码中文字字幕重口 | 91麻精品国产91久久久久| 久久婷婷五月综合国产尤物app| 久久久久亚洲av成人无码电影 | 91精品国产91久久久久久青草| 亚洲狠狠婷婷综合久久久久| 国产高清国内精品福利99久久| 久久精品黄AA片一区二区三区| 久久精品国产AV一区二区三区| 久久精品视屏| 久久久WWW成人| 蜜桃麻豆www久久国产精品| 久久99精品国产麻豆不卡| 午夜不卡888久久| 99久久精品国产综合一区| 72种姿势欧美久久久久大黄蕉| 九九久久自然熟的香蕉图片| 久久精品国产亚洲AV香蕉| 日产精品久久久一区二区| 色欲综合久久中文字幕网 | 国产激情久久久久影院小草| 97久久精品人人澡人人爽| 伊人色综合久久天天|