hdu 2069 Coin Change
来源:互联网 发布:淘宝修改折扣在哪里 编辑:程序博客网 时间:2024/04/28 04:54
http://acm.hdu.edu.cn/showproblem.php?pid=2069
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
#include<iostream>#include<cstdio>#include<cstring>using namespace std;int n,dp[110][300]; // dp[j][k] 统计到第i个coins k钱 dived to j 部分 的分法数int money[5]={1,5,10,25,50};int main(){ //freopen("input.txt","r",stdin); while(~scanf("%d",&n)){ memset(dp,0,sizeof(dp)); dp[0][0]=1; for(int i=0;i<5;i++) for(int j=1;j<=100;j++) for(int k=n;k>=money[i];k--) //这样写应该使对的,可写成这样for(int k=money[i];k<=n;k++) 也没WA,估计数据弱了 dp[j][k]+=dp[j-1][k-money[i]]; int ans=0; for(int i=0;i<=100;i++) //从0开始,注意 dp[0][0] ans+=dp[i][n]; printf("%d\n",ans); } return 0;}
#include<stdio.h>int main(){ int a,b,c,d,e,count,n; while(scanf("%d",&n)!=EOF) { count=0; for(a=0;a<=100;a++) for(b=0;5*b<=n;b++) for(c=0;10*c<=n;c++) for(d=0;25*d<=n;d++) for(e=0;50*e<=n;e++) if(a+5*b+10*c+25*d+50*e==n&&a+b+c+d+e<=100)count++; printf("%d\n",count); }}
#include<stdio.h>int main(){ int a[]={1,1,1,1,1,2,2,2,2,2,4,4,4,4,4,6,6,6,6,6,9,9, 9,9,9,13,13,13,13,13,18,18,18,18,18,24,24,24,24,24,31, 31,31,31,31,39,39,39,39,39,50,50,50,50,50,62,62,62,62,62, 77,77,77,77,77,93,93,93,93,93,112,112,112,112,112,134,134, 134,134,134,159,159,159,159,159,187,187,187,187,187,218,218, 218,218,218,252,252,252,252,252,292,291,291,291,291,333,333, 333,333,332,380,380,380,379,378,430,430,429,428,427,485,484, 483,482,482,544,543,542,541,539,608,607,606,604,602,677,676, 673,671,670,751,748,746,744,743,828,825,823,822,818,912,910, 908,904,900,1001,999,995,990,986,1098,1093,1088,1084,1081,1196, 1191,1186,1182,1177,1301,1296,1292,1285,1278,1413,1408,1400, 1393,1387,1532,1524,1515,1508,1503,1654,1644,1637,1631,1622,1782, 1773,1766,1757,1746,1916,1909,1898,1886,1875,2061,2049,2037,2025, 2015,2208,2194,2181,2170,2156,2361,2348,2336,2321,2306,2521,2508, 2492,2475,2459,2691,2673,2654,2637,2622,2863,2843,2824,2808,2789, 3042,3021,3004,2983,2960,3228,3209,3187,3164,3140,3424,3401,3376, 3351,3329,3623,3596,3570,3545,3517,3830,},n; while(scanf("%d",&n)!=EOF) printf("%d\n",a[n]);}
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
- 数据结构实验之二叉树的建立与遍历
- 1110. Complete Binary Tree (25)-PAT甲级真题
- error C2664: “AfxAssertFailedLine”: 不能将参数 1 从“TCHAR []”转换为“LPCSTR”
- 架构
- Invert Binary Tree
- hdu 2069 Coin Change
- VirtualBox复制虚拟机后丢失eth0网卡的解决办法
- 如何设置ofbiz的日志输出级别
- Java 集合系列13之 WeakHashMap详细介绍(源码解析)和使用示例
- C#开发-变量名的规则
- Q30:最小的k个数
- ofbiz的webservice接口提供(3)-不规范的wsdl的客户端访问代码
- 连续子数组的最大和
- 大数乘法