• <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
            典型的動(dòng)態(tài)規(guī)劃問(wèn)題:
            可以先考慮只有n-1種硬幣,V1,V2,V3,---Vn-1.設(shè)湊成總值為M的方法數(shù)為result[M];
            現(xiàn)在又添加一種面值為Vn的硬幣。
            則咱們需要修改一些值,修改那些大于等于Vn的result[],不妨設(shè)M大于vn。
            新result[M]=原result[M]+result[M-Vn]+result[M-2*Vn]+----直到M-p*Vn<=0;(1)
            實(shí)際上如果如(2)那樣處理 從大于等于Vn的result[]開(kāi)始處理的話,從小到大,設(shè)Vn=M-p*Vn;
            則result[M-p*Vn]第一個(gè)最先更新,result[M-p*Vn]+=result[M-p*Vn -Vn]   見(jiàn)(2)
            隨后更新result[M-(p-1)*vn],則只需直接加上result[M-p*Vn]的值,無(wú)需如(1)式那樣 累加。
            用程序表達(dá)就是
            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) //
            -------------
            還有一個(gè)注意點(diǎn),見(jiàn)牛人博客,http://hi.baidu.com/piaoshi111/blog/item/9a6de84a00a6e5f882025c89.html
            就是浮點(diǎn)數(shù)的四舍五入,
            1.5,浮點(diǎn)數(shù)可能表為1.4999999,所以乘以100時(shí)轉(zhuǎn)化為整型是149,應(yīng)當(dāng)注意。
            posted on 2009-07-19 21:45 luis 閱讀(487) 評(píng)論(0)  編輯 收藏 引用 所屬分類(lèi): 動(dòng)態(tài)規(guī)劃
            <2012年8月>
            2930311234
            567891011
            12131415161718
            19202122232425
            2627282930311
            2345678

            常用鏈接

            留言簿(3)

            隨筆分類(lèi)

            隨筆檔案

            文章分類(lèi)

            文章檔案

            友情鏈接

            搜索

            •  

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            99久久夜色精品国产网站| 97久久超碰成人精品网站| 一本久道久久综合狠狠躁AV| 亚洲精品无码久久久久AV麻豆| 三级三级久久三级久久| 国产Av激情久久无码天堂| 精品无码久久久久久久动漫| 国产香蕉久久精品综合网| 精品国产福利久久久| 色综合久久88色综合天天 | 久久ww精品w免费人成| 久久影院久久香蕉国产线看观看| 久久精品视频一| 国产精品激情综合久久| 综合久久国产九一剧情麻豆| 国产毛片久久久久久国产毛片| 无码人妻精品一区二区三区久久 | 国产午夜电影久久| 久久伊人五月丁香狠狠色| 国产精品欧美久久久久无广告| 亚洲va久久久噜噜噜久久男同| 精品一区二区久久| 亚洲AV无码成人网站久久精品大| 精品国产综合区久久久久久| 久久99久久99精品免视看动漫| 中文字幕无码久久久| 久久综合精品国产一区二区三区| 久久精品这里热有精品| 蜜臀av性久久久久蜜臀aⅴ | 亚洲午夜久久久久久久久电影网| 久久国产精品国语对白| 国产成人精品久久亚洲高清不卡| 久久精品中文闷骚内射| 性色欲网站人妻丰满中文久久不卡| 一本一本久久a久久精品综合麻豆| 国产精品成人无码久久久久久| 久久久久中文字幕| 91精品国产色综久久| 亚洲国产精品久久久久| 青青草原综合久久大伊人精品| 久久亚洲精品视频|