HDU 2069 Coin Change

Coin Change

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Problem 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
 
Author
Lily
 
Source
 

Recommend

linle   |   We have carefully selected several similar problems for you:  2152 2067 2065 2062 2059 
 
Statistic | Submit | Discuss | Note

 

水题毕竟还是水题,只是告诫我们要学好英语,看懂题意,233

 

请你用一定面值的货币(每种面值不限单独数量),组成一定金额,问方案数。注意使用的货币总数不能超过100个。

 

还是生成函数,只是为了满足总数不超过100个的奇怪要求,新增一维记录当前已经使用了多少个货币并稍微改动转移即可。

 

 1 #include <cstdio>
 2 #include <cstring>
 3 
 4 const int siz = 255;
 5 const int lim = 250;
 6 
 7 int n; 
 8 
 9 int f[105][siz];
10 int t[105][siz];
11 
12 const int s[5] = 
13 {
14     50,
15     25,
16     10,
17     5,
18     1
19 };
20 
21 signed main(void)
22 {
23     f[0][0] = 1;
24     
25     for (int p = 0; p < 5; ++p)
26     {
27         int c = s[p];
28         
29         memset(t, 0, sizeof t);
30         
31         for (int i = 0; i <= 100; ++i)
32             for (int j = 0; j <= lim; ++j)if (f[i][j])
33                 for (int k = 0; k * c <= lim; ++k)
34                     if (i + k <= 100 && j + k * c <= lim)
35                         t[i + k][j + k * c] += f[i][j];
36         
37         memcpy(f, t, sizeof f);
38     }
39     
40     for (int i = 1; i <= 100; ++i)
41         for (int j = 0; j <= lim; ++j)
42             f[i][j] += f[i - 1][j];
43     
44     while (scanf("%d", &n) != EOF)
45         printf("%d\n", f[100][n]);
46 }

 

@Author: YouSiki

 

posted @ 2017-02-21 15:26  YouSiki  阅读(268)  评论(0编辑  收藏  举报