zoukankan      html  css  js  c++  java
  • UVA 147(子集和问题)

     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_inline25 10c, 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


    思路:首先离线用dp求出范围内的所有答案。
        由于最小货币为5分;所以11种货币以5分为计算单位;
        令:
          b[i]为第i种货币含5分硬币的数量(0<=i&&i<11);
          a[i,j]用前i种货币构成j个5分硬币的方案数(0<=i&&i<11,0<=n&&n<=10000).仅用5分硬币所有可能值为a[1,j]=1;
                for(int i=1;i<11;i++)
                    for(int j=b[i];j<10000;j++){
                        a[j]+=a[j-b[i]];
                   }

        
     1 #include<iostream>
     2 #include<cstdio>
     3 #include<algorithm>
     4 #include<cstring>
     5 #include<cstdlib>
     6 #include<iomanip>
     7 #include<cmath>
     8 #include<vector>
     9 #include<queue>
    10 #include<stack>
    11 using namespace std;
    12 #define PI 3.141592653589792128462643383279502
    13 long long a[10000];
    14 int b[12]={1,2,4,10,20,40,100,200,400,1000,2000};
    15 int main(){
    16     //#ifdef CDZSC_June
    17     //freopen("in.txt","r",stdin);
    18     //#endif
    19     //std::ios::sync_with_stdio(false);
    20     for(int i=0;i<10000;i++) a[i]=1;
    21     for(int i=1;i<11;i++)
    22         for(int j=b[i];j<10000;j++){
    23             a[j]+=a[j-b[i]];
    24         }
    25     while(true){
    26         double n;
    27         scanf("%lf",&n);
    28         if(n==0.0) break;
    29         int s=int(n*20.0);
    30         printf("%6.2lf%17lld
    ",n,a[s]);
    31     }
    32     return 0;
    33 }
  • 相关阅读:
    山东第一届省赛1001 Phone Number(字典树)
    HD2222 Keywords Search(AC自动机入门题)
    POJ 1947Rebuilding Roads(树形DP + 01背包)
    zoj 3946 Highway Project(最短路 + 优先队列)
    HDU5672String(尺标法)
    HDU5671Matrix(矩阵行列交换)
    HDU5670Machine(抽象进制)
    用户体验评价
    团队冲刺第二阶段-6
    第十四周学习进度
  • 原文地址:https://www.cnblogs.com/yoyo-sincerely/p/5090060.html
Copyright © 2011-2022 走看看