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. 英语口语练习系列-C28-海滨-辨别身份-悬崖边的树

    beach 海滨 brown hut near body of water green trees near sea during daytime photography 海滨度假胜地 beach [ ...

  2. hibernate方法中参数传入数组的查询方法

    public List<T> getByIds(Long[] ids) { return getSession().createQuery(// "FROM User WHERE ...

  3. 修改Chrome启动参数解决跨域问题

    这个做法仅仅是针对自己本机,只是一个权宜方案 --disable-web-security --user-data-dir=本地用户信息目录 之后启动Chrome浏览器即可

  4. JS 之 script标签

    1.script标签 1.js代码的解析(包括下载js文件)会阻塞页面加载 2.当js文件放在头部,页面必须等所有js代码都被下载,解析和执行完成后才开始呈现页面内容(遇到body标签才呈现),对于那 ...

  5. UE4入门(一)软件安装教程

    基本的安装流程:下载并安装EpicInstaller=>登陆EpicLauncher并在UNREAL ENGINE标签中下载并安装引擎=>打开引擎创建新项目并测试 一 .下载并安装Epic ...

  6. swal() 弹出层的用法

    swal()方法是一个提示框: swal({ title: "", text: "请扫描用户手机上的付款码", type: "input", ...

  7. bzoj 1005

    prufer序列 性质: 1.一棵n个结点的树可表示为长度 n-2 的prufer序列 2.每个结点出现在prufer序列中的次数==该结点的度 -1 公式推出来了,大数模板没有除法..等开学了Jav ...

  8. python之接口与归一化设计

    1接口 接口的概念: Java 语言中的接口很好的展现了接口的含义: IAnimal.java /* * Java的Interface很好的体现了我们前面分析的接口的特征: * 1)是一组功能的集合, ...

  9. JS_高程3.基本概念(3)

    1.ECMAScript数值的范围 由于内存的限制,在大多数浏览器中,ECMAScript能够拿保存的数据的范围是 5e-324 ~ 1.7976931348623157e+308,其中最小的数值保存 ...

  10. 简易RPC框架-SPI

    *:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...