经典DP:固定钱能换多少次+硬币个数限制(2069)
来源:互联网 发布:上海斑马公寓知乎 编辑:程序博客网 时间:2024/05/22 00:40
Coin Change
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 16932 Accepted Submission(s): 5802
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
Sample Output
413
/*------------------Header Files------------------*/#include <iostream>#include <cstring>#include <string>#include <cstdio>#include <algorithm>#include <cstdlib>#include <ctype.h>#include <cmath>#include <stack>#include <queue>#include <deque>#include <map>#include <vector>#include <limits.h>using namespace std;/*------------------Definitions-------------------*/#define LL long long#define PI acos(-1.0)#define INF 0x3F3F3F3F#define MOD 10E9+7#define MAX 500050/*---------------------Work-----------------------*/int dp[500][200];int coin[]={0,50,25,10,5,1};void work(){dp[0][0]=1;for(int i=1;i<=5;i++)for(int j=0;j<=250;j++)for(int k=0;k<100;k++)if(coin[i]+j<=250)dp[coin[i]+j][k+1]+=dp[j][k];else break;int n;while(scanf("%d",&n)==1){int sum=0;for(int i=0;i<=100;i++)sum+=dp[n][i];printf("%d\n",sum);}}/*------------------Main Function------------------*/int main(){//freopen("test.txt","r",stdin);//freopen("cowtour.out","w",stdout);//freopen("cowtour.in","r",stdin);work();return 0;}
0 0
- 经典DP:固定钱能换多少次+硬币个数限制(2069)
- 硬币问题 经典dp
- 硬币问题(经典dp)
- 入门经典--硬币问题dp递归加递推
- DP经典应用(五)硬币问题
- 硬币个数
- poj 1787 求达到总钱数的选硬币的最大数量(硬币有个数限制)
- textarea限制每行可输入固定个数的字符
- 平均抛多少次硬币能连抛两次“字”
- UVA 674 Coin Change 换硬币 经典dp入门题
- hdu1085 母函数的应用之每种硬币有个数限制
- 【DP】hdu_1799_循环多少次_201407311017
- XTU 1233 n个硬币连续m个正面个数(dp)
- 硬币组合问题之最少硬币个数
- 【dp】最少硬币问题
- DP 换硬币问题
- uva 11137(硬币dp)
- uva 10313(硬币dp)
- 同一台服务器运行多套kamailio服务
- Android实现播放GIF动画的强大ImageView
- Zookeeper - 开发篇(1)
- 平衡树Treap模版
- POJ 2482 Stars in Your Window 线段树+扫描线
- 经典DP:固定钱能换多少次+硬币个数限制(2069)
- JAVA的File类详解之目录列表器
- 第十三章 字符串
- Linux系统调用
- iOS -- 处理推送消息
- 程序国际化及动态处理文本
- ListView 优化篇:从 BaseViewHolder 到面向 Holder 的思想
- 详解 CSS 属性 - 伪类和伪元素的区别
- network