杭电2069之Coin Change
来源:互联网 发布:java编码哪个是中文的 编辑:程序博客网 时间:2024/06/06 19:10
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
分析:
暴力枚举算法,不过要考虑是否超时,需要缩小范围!!!
AC代码如下:
#include "iostream"using namespace std;int main(int argc, char* argv[]){ int i,j,k,l,m; int n,count; while(cin>>n) { count=0; for (m=0;m<=5;m++) for (l=0;l<=10-2*m;l++) for (k=0;k<=25-5*m;k++) for (j=0;j<=50-2*k;j++) for(i=0;i<=100;i++) if (i*1+j*5+k*10+l*25+m*50==n&&i+j+k+l+m<=100) { count++; } cout<<count<<endl; } return 0;}
0 0
- 杭电2069之Coin Change
- 杭电 2069 Coin Change
- 杭电hdu 2069 Coin Change 母函数
- leetcode之Coin Change
- leetcode之 coin change
- HDU 2069 Coin Change
- hdu 2069 Coin Change
- HDU 2069 Coin Change
- HDU 2069 Coin Change
- hdu 2069 Coin Change
- HDOJ 2069 Coin Change
- HDUJ 2069 Coin Change
- HDOJ 2069 coin change
- HDU 2069 Coin Change
- hdu 2069 Coin Change
- hdu 2069 Coin Change
- hdu-2069-Coin Change
- HDU 2069 Coin Change
- 垃圾回收与构造方法
- VS”不能设置下面断点“和”无法单步执行“问题
- table标签,认识网页上的表格
- java基础知识:栈内存和堆内存
- Android 四大组件的工作过程
- 杭电2069之Coin Change
- 根据main函数中对printchs函数的调用,以及printchs的功能要求,编写printchs函数,使下面的程序能输出星号图:
- Android MVP模式
- 用css样式,为表格加入边框
- 关于volatile关键字
- leetcode_c++:Missing Number(268)
- dagger2深入学习
- Greenplum或DeepGreen的管理数据
- 准备 LVM Volume Provider - 每天5分钟玩转 OpenStack(49)