HDU2069 Coin Change 【暴力】
来源:互联网 发布:三级网络技术题库软件 编辑:程序博客网 时间:2024/05/22 19:01
Coin Change
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 13500 Accepted Submission(s): 4510
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 <stdio.h>int main(){ int n, a, b, c, d, e, ans; while(scanf("%d", &n) == 1){ ans = 0; for(a = 0; a <= n/50; ++a) for(b = 0; b <= n/25; ++b) for(c = 0; c <= n/10; ++c) for(d = 0; d <= n/5; ++d) for(e = 0; e <= n; ++e) if(a*50 + b*25 + c*10 + d*5 + e == n && a+b+c+d+e <= 100) ++ans; printf("%d\n", ans); } return 0;}
提交代码:
#include <stdio.h>const int dp[] = {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};int main(){ int n; while(scanf("%d", &n) == 1) printf("%d\n", dp[n]); return 0;}
0 0
- HDU2069 Coin Change 【暴力】
- HDU2069 Coin Change(暴力)
- HDU2069 Coin Change,背包
- HDU2069 Coin Change 背包
- HDU2069 Coin Change
- HDU2069 Coin Change (DP)
- 【HDU2069】【Coin Change】
- hdu2069 Coin Change
- Coin Change(hdu2069,暴力or母函数)
- 【背包/母函数】HDU2069-Coin Change
- Coin Change(暴力枚举)
- 【母函数】hdu2069(Coin Change)母函数加深
- HDU 2069 Coin Change (暴力)
- 【HDU】2069 - Coin Change(暴力)
- 【HDU 2069】Coin Change 暴力枚举法
- HDU2069 Coin change HDU 1114 Piggy-Bank HDU1712 ACboy needs your help
- HDU2069 & UVA 674 Coin Change(换硬币 dp 入门经典水题,背包问题)
- hdu2069 暴力打表
- HDU 4968 Improving the GPA 模拟
- Android 动画原理
- 发布与运行 Oracle Fusion Order Demo
- UVA 662 - Fast Food
- 使用github之:Git远程操作详解
- HDU2069 Coin Change 【暴力】
- ADF 11g 问与答
- Python除法使用注意
- 华为软件研发面试题2
- java 基础之成员变量,成员方法和局部变量,实例方法
- 在iPhone安装OpenSSH和远程连接教程
- 条款09:绝不在构造和西欧过程中调用virtual函数
- MySQL 按条件导出某部分数据
- 华为软件研发面试题1