hdu2069 Coin Change
来源:互联网 发布:编程解决鸡兔同笼 编辑:程序博客网 时间:2024/06/07 02:49
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
思路
二维母函数,由于硬币总数<=100,还需要开辟一个数组记录用的硬币数
/************************************************************************* > File Name: hdu2069.cpp > Author:gens_ukiy > Mail: > Created Time: 2016年11月30日 星期三 16时45分06秒 ************************************************************************/#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<vector>#include<set>#include<list>#include<map>using namespace std;#define rep(i,a,b) for(int i=(a);i<=(b);(i++))#define inf 0x3f3f3f#define ll long long#define maxn 255int c1[maxn][105],c2[maxn][105],re[maxn];int main(){ int n; int coin[5]={1,5,10,25,50}; memset(c1,0,sizeof(c1)); memset(c2,0,sizeof(c2)); c1[0][0]=1; rep(i,0,4) { rep(j,0,250) for(int k=0;k*coin[i]+j<=250;k++) for(int p=0;k+p<=100;p++) c2[j+k*coin[i]][p+k] += c1[j][p]; rep(j,0,250) rep(p,0,100) c1[j][p]=c2[j][p],c2[j][p]=0; } rep(i,1,250) rep(j,0,100) re[i] += c1[i][j]; re[0]=1; while(cin>>n) printf("%d\n",re[n]); return 0;}
- HDU2069 Coin Change,背包
- HDU2069 Coin Change 背包
- HDU2069 Coin Change 【暴力】
- HDU2069 Coin Change
- HDU2069 Coin Change (DP)
- 【HDU2069】【Coin Change】
- HDU2069 Coin Change(暴力)
- hdu2069 Coin Change
- 【背包/母函数】HDU2069-Coin Change
- Coin Change(hdu2069,暴力or母函数)
- 【母函数】hdu2069(Coin Change)母函数加深
- HDU2069 Coin change HDU 1114 Piggy-Bank HDU1712 ACboy needs your help
- HDU2069 & UVA 674 Coin Change(换硬币 dp 入门经典水题,背包问题)
- Coin Change
- Coin Change
- Coin change
- Coin Change
- Coin change
- Android 心跳连接功能 bindService()无法启动Service的问题
- 1006. 换个格式输出整数 (15)
- android data binding实践之:ViewDataBinding
- mysql 函数与存储过程及区别
- ReactiveCocoa 中 RACSignal 所有变换操作底层实现分析(上)
- hdu2069 Coin Change
- HDU 1023 Train Problem II(Catalan + 大数)
- 设计模式-单例
- matlab 2016a 破解版安装教程
- 苹果退出有两种方式:exit(0);和abort();
- BZOJ 1588 [HNOI2002]营业额统计
- loadView,viewDidLoad,viewDidUnload
- 安卓案例-简单图片查看器
- TCP接收缓存大小的动态调整