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. [No000034]知乎-长期接收碎片化知识有什么弊端?

    你所接受的一切信息,构成了你的思维方式. 所以,长期接受碎片信息的后果,就是让你的思维变得狭隘,难以进行复杂的思考. 碎片信息通常具备这样的特征: •它们往往是一些事实的集合而非逻辑 •它们往往大量简 ...

  2. 转: 使用Eclipse的Working Set,界面清爽多了

    from: http://iyuanbo.iteye.com/blog/1158136 使用Eclipse的Working Set,界面清爽多了   想必大家的Eclipse里也会有这么多得工程... ...

  3. box-shadow 的一些使用

    1.只有左侧有阴影 box-shadow: -10px 0px 3px 1px #aaaaaa;

  4. 程序员级别鉴定书(.NET面试问答集锦)

    作为一个.NET程序员,应该知道的不仅仅是拖拽一个控件到设计时窗口中.就像一个赛车手,一定要了解他的爱车 – 能做什么不能做什么. 本文参考Scott Hanselman给出的.NET问题列表,整理如 ...

  5. mysql线上一个定时备份脚本

    数据库服务使用的是阿里云的mysql,远程进行定时的全量备份,备份到本地,以防万一.mysql数据库远程备份的数据最好打包压缩: [root@huanqiuPC crontab]# pwd/Data/ ...

  6. javascript中的链表结构—从链表中删除元素

    1.概念 上一个博文我们讲到链表,其中有一个方法remove()是暂时注释的,这个方法有点复杂,需要添加一个Previous()方法找到要删除的元素的前一个节点,这一个博文我们来分析一下这个remov ...

  7. android中常用的读取文件的用法如下

    1. 从resource的raw中读取文件数据: String res = ""; try{ //得到资源中的Raw数据流 InputStream in = getResource ...

  8. 工作随笔——一次简单的Maven加速构建实战

    注意:所有的编译.打包.部署全部是通过Jenkins完成的. 公司内部有一个项目,开始做的时候已经预计到会有很多客服端.所以开发就搞了如下的结构: fft-api # 公用的API,所有的程序都必须使 ...

  9. mongodb .net core 调用

    MongoClient _client; IMongoDatabase _db; MongoCredential credential = MongoCredential.CreateMongoCRC ...

  10. 关于mvc5+EF里面的db.Entry(model).State = EntityState.Modified报错问题

    最近在使用mvc5+EF的的时候用到了这句话 db.Entry(model).State = EntityState.Modified 看上去很简单的修改数据,但是一直报错,说是key已经存在,不能修 ...