hdu 2069 Coin Change
来源:互联网 发布:2015年淘宝全年交易额 编辑:程序博客网 时间:2024/04/28 16:50
Coin Change
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 13471 Accepted Submission(s): 4493
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.
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
1126/*题解: 随着做母函数题数的增多,发现用一位数组解母函数问题越来越无力,以后有个数限制的尽量用二维数组吧。 其实有数量限制的题是可以用暴力枚举解的,但仅仅用枚举的话,不仅自己失去了学习母函数的机会,题目也失去了意义,变成简单的水题。 就和解大数问题一样,java都能水过,为什么还用C?因为学的是过程、思想,而不是简简单单要个A! 言归正传,此题用二维数组做(先打好表),例如:c1[a][b],a指的是钱数,b指的是钱币的个数。 */#include<cstdio>#include<cstring>int c1[1010][1010],c2[1010][1010];int main(){ int i,j,k,n,h,sum,coin[5]={1,5,10,25,50}; memset(c1,0,sizeof(c1)); memset(c2,0,sizeof(c2)); for(i=0; i<=250; i+=coin[0]) //对第一个括号内的数据初始化 c1[i][i]=1; for(i=1; coin[i]<=250&&i<=4; i++) { for(j=0; j<=250; j++) { for(k=0; k+j<=250; k+=coin[i]) { for(h=0; h+k/coin[i]<=100; h++) c2[k+j][h+k/coin[i]]+=c1[j][h]; } } for(j=0; j<=250; j++) for(h=0; h<=100; h++) { c1[j][h]=c2[j][h]; c2[j][h]=0; } } while(scanf("%d",&n)!=EOF) { for(i=0,sum=0; i<=100; i++) sum+=c1[n][i]; printf("%d\n",sum); } return 0;}
0 0
- HDU 2069 Coin Change
- hdu 2069 Coin Change
- HDU 2069 Coin Change
- HDU 2069 Coin Change
- hdu 2069 Coin Change
- HDU 2069 Coin Change
- hdu 2069 Coin Change
- hdu 2069 Coin Change
- hdu-2069-Coin Change
- HDU 2069 Coin Change
- hdu---2069Coin Change
- HDU 2069 Coin Change
- HDU 2069 Coin Change
- HDU-2069-Coin Change
- hdu 2069 Coin Change
- HDU#2069: Coin Change
- HDU - 2069 - Coin Change
- HDU:2069 Coin Change
- 6个不可违背的“手机思维”
- HDU 4849 Wow! Such City! (Dijkstra, 最短路)
- linux安装gnome产生 Failed to connect to system bus问题
- Python中datetime类错误
- 博弈论详解
- hdu 2069 Coin Change
- Linux常用命令【归纳】【熟记】(一)—— 文件归档与压缩/解压
- 测试
- ETL调度开发(1)——编写说明
- 未来医疗健康领域的平台不会只有BAT
- 迭代部分习题
- UVA208
- ubuntu命令的使用
- C++内存泄漏的检测