Coin Change

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

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
 
Author
Lily
 
题意: 能不能用1 5 10 25 50 组成输入的数,并且使用的个数不能超过100个。
 
思路:
多加一维维护个数。a[j][l] 表示值为j,用了l个的时候有多少种方案。
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define INF 1000000001
#define MOD 1000000007
#define ll long long
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define pi acos(-1.0)
using namespace std;
const int MAXN = ;
int c[MAXN][],tp[MAXN][],n,val[];
int main()
{
val[] = ,val[] = ,val[] = ,val[] = ,val[] = ;
while(~scanf("%d",&n)){
if(!n){
puts("");
continue;
}
memset(c,,sizeof(c));
memset(tp,,sizeof(tp));
for(int i = ; i <= min(n,); i++){
c[i][i] = ;
}
for(int i = ; i <= ; i++){
for(int j = ; j <= n; j++){
for(int k = ; k + j <= n; k += val[i]){
for(int l = ; l + k / val[i] <= ; l ++){
tp[j + k][l + k / val[i]] += c[j][l];
}
}
}
for(int j = ; j <= n; j++){
for(int k = ; k <= ; k++){
c[j][k] = tp[j][k];
tp[j][k] = ;
}
}
}
int ans = ;
for(int i = ; i <= ; i++){
ans += c[n][i];
}
cout<<ans<<endl;
}
return ;
}

hdu 2069 限制个数的母函数(普通型)的更多相关文章

  1. HDU 1284 钱币兑换问题(普通型 数量无限的母函数)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1284 钱币兑换问题 Time Limit: 2000/1000 MS (Java/Others)    ...

  2. hdu 2069 1 5 10 25 50 这几种硬币 一共100个(母函数)

    题意: 有50 25 10 5 1 的硬币 一共最多有100枚 输入n输出有多少种表示方法 Sample Input1126 Sample Output413 # include <iostre ...

  3. HDU 1284(钱币兑换 背包/母函数)

    与 HDU 1028 相似的题目. 方法一:完全背包. 限制条件:硬币总值不超过 n. 目标:求出组合种数. 令 dp[ i ][ j ] == x 表示用前 i 种硬币组合价值为 j 的钱共 x 种 ...

  4. HDU 2082 找单词 (普通母函数)

    题目链接 Problem Description 假设有x1个字母A, x2个字母B,..... x26个字母Z,同时假设字母A的价值为1,字母B的价值为2,..... 字母Z的价值为26.那么,对于 ...

  5. HDU——2083找单词(母函数)

    找单词 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submissio ...

  6. HDU 1521 排列组合 (母函数)

    题目链接 Problem Description 有n种物品,并且知道每种物品的数量.要求从中选出m件物品的排列数.例如有两种物品A,B,并且数量都是1,从中选2件物品,则排列有"AB&qu ...

  7. HDU 1171 Big Event in HDU 杭电大事件(母函数,有限物品)

    题意: 分家问题,对每种家具都估个值,给出同样价值的家具有多少个,要求尽可能平分,打印的第一个数要大于等于第二个数. 思路: 可以用背包做,也可以用母函数.母函数的实现只需要注意一个点,就是每次以一种 ...

  8. Ignatius and the Princess III HDU - 1028 || 整数拆分,母函数

    Ignatius and the Princess III HDU - 1028 整数划分问题 假的dp(复杂度不对) #include<cstdio> #include<cstri ...

  9. 题解报告:hdu 1398 Square Coins(母函数或dp)

    Problem Description People in Silverland use square coins. Not only they have square shapes but also ...

随机推荐

  1. POJ1523 SPF[无向图割点]

    SPF Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8139   Accepted: 3723 Description C ...

  2. ExecutorType 的类型

  3. poj1190

    生日蛋糕 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 18230 Accepted: 6491 Description 7月1 ...

  4. CSS3 Media Queries 片段

    CSS3 Media Queries片段 在这里主要分成三类:移动端.PC端以及一些常见的响应式框架的Media Queries片段. 移动端Media Queries片段 iPhone5 @medi ...

  5. ASP.NET 中执行 URL 重写

    具体实现步骤(其中的一种实现方法): 一.下载相关的DLL(ActionlessForm.dll和UrlRewriter.dll) http://download.csdn.net/detail/yi ...

  6. distributed caching for .net applications

    distributed caching for .net applications fast, scalable distributed caching with meaningful perform ...

  7. css 内容超过容器宽度,checkbox等控件不会随着内容延伸

    <div a> <div id='内容容器'> <div>很长的内容</div><input type='checkbox'/> </ ...

  8. Ice的HelloWorld(Java)

    Ice是一种面向对象的中间间平台,入门ice,简单的HelloWorld是必不可少的. 转载请注明http://www.cnblogs.com/zrtqsk/p/3745286.html,谢谢. 一. ...

  9. [C]基本数据类型:整型(int)用法详解

    1.整型int C语言提供了很多整数类型(整型),这些整型的区别在于它们的取值范围的大小,以及是否可以为负.int是整型之一,一般被称为整型.以后,在不产生歧义的情况下,我们把整数类型和int都称为整 ...

  10. 关于printf函数的所思所想

    缘起大一下学期,C语言程序设计徐小青老师的随口一提,经娄嘉鹏老师提醒,我觉得应该自己整理清楚这一问题.涉及网上资料将会标明出处. 关于printf函数的所思所想 * printf的定义 printf( ...