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. Codeforces 410C.Team[构造]

    C. Team time limit per test 1 second memory limit per test 256 megabytes input standard input output ...

  2. POJ1276Cash Machine[多重背包可行性]

    Cash Machine Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 32971   Accepted: 11950 De ...

  3. Windows 10 UWP开发:如何不让界面卡死

    http://edi.wang/post/2016/2/18/windows-10-uwp-async-await-ui-thread 关于UI线程 这里我们需要一点关于 UI 线程模型的概念,简单的 ...

  4. JVM再了解了解

    转自 http://www.cnblogs.com/Coda/p/4331432.html 相信大家已经了解到Java具有跨平台的特性,可以“一次编译,到处运行”,在Windows下编写的程序,无需任 ...

  5. C#复习(学生信息输入)

    在控制台程序中使用结构体.集合,完成下列要求项目要求:一.连续输入5个学生的信息,每个学生都有以下4个内容:1.序号 - 根据输入的顺序自动生成,不需要手动填写,如输入第一个学生的序号是1,第二个是2 ...

  6. 南邮oj[1401] 乘车费用

    Description lqp家离学校十分十分远,同时他又没有钱乘taxi.于是他不得不每天早早起床,匆匆赶到公交车站乘车到学校.众所周知CZ是个公交车十分发达的地方,但是CZ的公交车十分的奇怪,lq ...

  7. poj1129 Channel Allocation

    Channel Allocation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14361   Accepted: 73 ...

  8. vs2013怎么打开vs2010的解决方案

    1.直接用vs2013打开解决方案的sln文件,vs会自动进行转换的2.或者你用记事本的方式打开sln文件 将版本号改一下Microsoft Visual Studio Solution File, ...

  9. codevs2010 求后序遍历

    难度等级:白银 2010 求后序遍历 题目描述 Description 输入一棵二叉树的先序和中序遍历序列,输出其后序遍历序列. 输入描述 Input Description 共两行,第一行一个字符串 ...

  10. Python快速教程目录(转)

    作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 怎么能快速地掌握Python?这是和朋友闲聊时谈起的问题. Python包含的内容 ...