zoukankan      html  css  js  c++  java
  • HDU 2069 Coin Change

    Description

    Suppose there are 5 types of coins: 50-cent, 25-cent, 10-cent, 5-cent, and 1-cent. We want to make changes with these coins for a given amount of money.

    For example, if we have 11 cents, then we can make changes with one 10-cent coin and one 1-cent coin, or two 5-cent coins and one 1-cent coin, or one 5-cent coin and six 1-cent coins, or eleven 1-cent coins. So there are four ways of making changes for 11 cents with the above coins. Note that we count that there is one way of making change for zero cent.

    Write a program to find the total number of different ways of making changes for any amount of money in cents. Your program should be able to handle up to 100 coins.
     

    Input

    The input file contains any number of lines, each one consisting of a number ( ≤250 ) for the amount of money in cents.
     

    Output

    For each input line, output a line containing the number of different ways of making changes with the above 5 types of coins.
     

    Sample Input

    11 26
     

    Sample Output

    4 13
    有技巧的暴力,开始没发现那个100,一直wa,还不知道错误在那
     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cmath>
     4 using namespace std;
     5 int main()
     6 {
     7     int n;
     8     int i,j,k,u,t;
     9     int sum;
    10     while(cin>>n)
    11     {
    12         sum=0;
    13         for(i=0;i<=n;i++)
    14         {
    15             for(j=0;5*j<=(n-i);j++)
    16             {
    17                 for(k=0;10*k<=(n-j*5-i);k++)
    18                 {
    19                     for(u=0;25*u<=(n-i-5*j-10*k);u++)
    20                     {
    21                         for(t=0;50*t<=(n-i-5*j-10*k-25*u);t++)
    22                         {
    23 
    24                             if(i+5*j+k*10+25*u+50*t==n&&i+j+k+u+t<=100)
    25                             {
    26                                 sum++;
    27                             }
    28                         }
    29                     }
    30                 }
    31             }
    32         }
    33         cout<<sum<<endl;
    34     }
    35     return 0;
    36 }
  • 相关阅读:
    做题记录
    关于有向图强连通分量的一点想法
    浅谈二分图匹配(未完)
    水题狂欢赛 (爬楼梯赛)题解(偏向自我反省)
    浅谈迭代加深(iddfs)
    浅谈单调队列优化
    [cqbzoj#10644]鱼肉炸弹题解
    树形背包[2/ 50] luogu [P1273]
    树形背包[1/ 50] luogu [P2015] (超级板)
    (树状数组)区间修改,区间查询
  • 原文地址:https://www.cnblogs.com/Aa1039510121/p/5689871.html
Copyright © 2011-2022 走看看