zoukankan      html  css  js  c++  java
  • uva 147 Dollars

     Dollars 

    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 tex2html_wrap_inline25 20c, 2 tex2html_wrap_inline2510c, 10c+2 tex2html_wrap_inline25 5c, and 4 tex2html_wrap_inline25 5c.

    Input

    Input will consist of a series of real numbers no greater than $300.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 6), followed by the number of ways in which that amount may be made up, right justified in a field of width 17.

    Sample input

    0.20
    2.00
    0.00

    Sample output

      0.20                4
      2.00              293

    和上一道模板题差不多,因为有小数,但是最多两位小数,所以所有数据直接变成20倍计算。注意输出格式。

    题意:11种钱币,指定钱的数额,输出最大组成数。

    附上代码:

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 using namespace std;
     5 long long dp[6005];
     6 int main()
     7 {
     8     int i,j,m;
     9     int coin[11]= {1,2,4,10,20,40,100,200,400,1000,2000};
    10     memset(dp,0,sizeof(dp));
    11     dp[0]=1;
    12     for(i=0; i<11; i++)
    13         for(j=coin[i]; j<=6000; j++)
    14             dp[j]+=dp[j-coin[i]];
    15     double n;
    16     while(~scanf("%lf",&n))
    17     {
    18         m=(int)(n*20);
    19         if(m==0) break;
    20         printf("%6.2lf%17lld
    ",n,dp[m]);
    21     }
    22     return 0;
    23 }
  • 相关阅读:
    PHP数组操作,数组排序,数组元素操作,数组元素定位
    提高PHP编程效率的53个要点
    javascript的一些简单的应用
    数字时钟
    一个限定变量范围的小技巧
    windows编程学习——1 关闭窗口不退出
    比木马NB多了
    模拟时钟
    恶搞程序——黑屏
    用白色画笔再画一遍,代替擦除
  • 原文地址:https://www.cnblogs.com/pshw/p/5173191.html
Copyright © 2011-2022 走看看