Coin Change

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 18271    Accepted Submission(s): 6291

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

找零钱问题,但是限制了一次找零的硬币数量

下面就直接暴力了

#include <iostream>

using namespace std;

const int Max = ;
const int a[] = {,,,,};
long dp[Max]; void change()
{
dp[] = ;
for (int m = ; m <= Max; m++)
{
for (int i50 = ; i50 <= m / ; i50++)
{
for (int i25 = ; i25 <= (m - i50 * ) / ; i25++)
{
for (int i10 = ; i10 <= (m - i50 * - i25 * ) / ; i10++)
{
for (int i5 = ; i5 <= (m - i50 * - i25 * - i10 * ) / ; i5++)
{
int i1 = m - i50 * - i25 * - i10 * - i5 * ;
if (i1 >= && i1 + i5 + i10 + i25 + i50 <= )
{
dp[m]++;
}
}
}
}
}
} }
int main()
{
int money;
change();
while (cin >> money)
{
cout << dp[money] << endl;
}
}

hdoj:2069的更多相关文章

  1. 算法——A*——HDOJ:1813

    Escape from Tetris Time Limit: 12000/4000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  2. HDOJ:1533-Going Home(最小费用流)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1533 解题心得: 第一次写最小费用流的题,去hdoj上找了一个入门级题目,建图比较简单,用了spfa和 ...

  3. hdoj:2086

    A1 = ? Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Subm ...

  4. hdoj:2085

    核反应堆 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  5. hdoj:2084

    数塔 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submissi ...

  6. hdoj:题目分类

    基础题: 1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028.1029.1032.1037.1040.1048.1056.1058. ...

  7. HDOJ:6333-Problem B. Harvest of Apples(组合数学+莫队算法+逆元)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6333 解题心得: 这个题可以说是十分精彩了,首先推组合数学的公式,其中一个很重要的公式是Cnm = C ...

  8. HDOJ:6356-Glad You Came(线段树剪枝)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6356 解题心得: 现在深深的知道了算法复杂度的重要了,这个题算复杂度的时候还要把一些常数也算出来,不然 ...

  9. hdoj:2075

    A|B? Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

随机推荐

  1. Codeforces.1096E.The Top Scorer(组合)

    题目链接 感觉这题很裸啊,除了看着恶心点也没什么了,怎么过的人那么少.. \(Description\) 给定\(n,r,s\),表示有\(n\)个人,设每个人的得分是非负整数\(a_i\),已知第一 ...

  2. 流畅的Python——切片

    2.4 切片 在 Python 里,像列表(list).元组(tuple)和字符串(str)这类序列类型都支持切片操作,但是实际上切片操作比人们所想象的要强大很多. 在我个人的使用经历来看,在算法实践 ...

  3. 封装、property特性及绑定与非绑定方法

    1.封装 (1)什么是封装? 封:属性对外是隐藏的,但对内是开放的: 装:申请一个名称空间,往里面装入一系列名字/属性 (2)为什么要封装? 封装数据属性的目的 首先定义属性的目的就是为了给类外部的使 ...

  4. 编程菜鸟的日记-初学尝试编程-编写函数实现strcmp功能

    #include <iostream>using namespace std;int mystrcmp(const char *str1,const char *str2){ assert ...

  5. Map集合架构总结

    说明;这里先学习Map集合,然后再学习Set集合,是因为Set集合中的HashSet依赖于hashMap,就是通过hashMap集合来实现的,TreeSet集合依赖于TreeMap集合,TreeSet ...

  6. java基础知识总结--对象的克隆

    前提:在Java语言中所有的类的都是缺省的继承Java语言中的Object类的, protected native Object clone() throws CloneNotSupportedExc ...

  7. RS485 VS 20mA 电流环

    RS485采用差分信号负逻辑,+2V-+6V表示“0”,- 6V-- 2V表示“1”.RS485有两线制和四线制两种接线,四线制只能实现点对点的通信方式,现很少采用,现在多采用的是两线制接线方式,这种 ...

  8. java内部类(二)

    静态内部类 定义: static修饰的内部类就是静态内部类. 特点: 1.静态内部类不能直接访问外部类的非静态成员,但可以通过new 外部类().成员 的方式访问. 2.如果外部类的静态成员与内部类成 ...

  9. [asp.net core]The requested page cannot be accessed because the related configuration data for the page is invalid.

    bug HTTP Error 500.19 - Internal Server Error The requested page cannot be accessed because the rela ...

  10. mac下svn提交失败的解决方法

    $svn ci maps.xml然后出现一个文件svn-commit.4.tmp,在文件svn-commit.4.tmp中有如下内容:   --This line, and those below, ...