HDU 1085 Holding Bin-Laden Captive! (母函数)
Holding Bin-Laden Captive!
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 13861 Accepted Submission(s): 6230
“Oh, God! How terrible! ”

Don’t be so afraid, guys. Although he hides in a cave of Hang Zhou, he dares not to go out. Laden is so bored recent years that he fling himself into some math problems, and he said that if anyone can solve his problem, he will give himself up!
Ha-ha! Obviously, Laden is too proud of his intelligence! But, what is his problem?
“Given some Chinese Coins (硬币) (three kinds-- 1, 2, 5), and their number is num_1, num_2 and num_5 respectively, please output the minimum value that you cannot pay with given coins.”
You, super ACMer, should solve the problem easily, and don’t forget to take $25000000 from Bush!
1 1 3
0 0 0
4
题意:给定三中硬币,面值分别为1,2,5,而且给定三种硬币的数量分别为num_1,num_2,num_5,然后让求解这些硬币所不能组成的最小的面额是多少,比如给定的样例。面值为1的硬币为1枚,面值为2的硬币为1枚,面值为5的硬币为3枚,则能够组成的面值有1,2,3,5......所以,不能组成的最小面额为4。
这就是一道母函数的问题,可是这里并非求组合数。所以,不须要int行的数组来记录组合数,仅仅须要true和false来标示能否表示该面值就能够了。当然用int记录组合数也能够,但要注意。由于组合量很大,要注意溢出的情况,我试了一下能够,推断大于0的时候置1就能过。
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <cstring>
#include <algorithm> using namespace std; const int MAX = 8003;
const int type[3] = {1,2,5}; bool ans[MAX],tmp[MAX];
int cnt[3]; void work(){
int i,j,k; memset(ans,0,sizeof(ans));
memset(tmp,0,sizeof(tmp)); for(i=0;i<=cnt[0];++i){
ans[i] = true;
} //(author : CSDN iaccepted)
for(i=1;i<3;++i){
for(j=0;j<=MAX;++j){
for(k=0;k<=cnt[i] && j+k*type[i]<=MAX;++k){
//tmp[j+k*type[i]] += ans[j];
if(tmp[j+k*type[i]] || ans[j])tmp[j+k*type[i]] = true;
}
}
for(j=0;j<=MAX;++j){
ans[j] = tmp[j];
tmp[j] = false;
}
}
} int main(){
//freopen("in.txt","r",stdin);
//(author : CSDN iaccepted)
int res,i;
while(scanf("%d %d %d",&cnt[0],&cnt[1],&cnt[2])!=EOF){
if(cnt[0]==0 && cnt[1]==0 && cnt[2]==0)break;
work();
for(i=0;i<=MAX;++i){
if(!ans[i]){
res = i;
break;
}
}
printf("%d\n",res);
}
return 0;
}
HDU 1085 Holding Bin-Laden Captive! (母函数)的更多相关文章
- HDU 1085 Holding Bin-Laden Captive!(母函数,或者找规律)
Holding Bin-Laden Captive! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...
- HDOJ/HDU 1085 Holding Bin-Laden Captive!(非母函数求解)
Problem Description We all know that Bin-Laden is a notorious terrorist, and he has disappeared for ...
- HDU 1085 Holding Bin-Laden Captive! 活捉本拉登(普通型母函数)
题意: 有面值分别为1.2.5的硬币,分别有num_1.num_2.num_5个,问不能组成的最小面值是多少?(0<=每种硬币个数<=1000,组成的面值>0) 思路: 母函数解决. ...
- hdu 1085 Holding Bin-Laden Captive! (母函数)
//给你面值为1,2,5的三种硬币固定的数目,求不能凑出的最小钱数 //G(x)=(1+x+...+x^num1)(1+x^2+...+x^2num2)(1+x^5+,,,+x^5num3), //展 ...
- HDU 1085 Holding Bin-Laden Captive!(DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1085 解题报告:有1,2,5三种面值的硬币,这三种硬币的数量分别是num_1,num_2,num_5, ...
- hdu 1085 Holding Bin-Laden Captive!
Problem Description We all know that Bin-Laden is a notorious terrorist, and he has disappeared for ...
- HDU 1085 Holding Bin-Laden Captive --生成函数第一题
生成函数题. 题意:有币值1,2,5的硬币若干,问你最小的不能组成的币值为多少. 解法:写出生成函数: 然后求每项的系数即可. 因为三种硬币最多1000枚,1*1000+2*1000+5*1000=8 ...
- hdu 1085 给出数量限制的母函数问题 Holding Bin-Laden Captive!
Holding Bin-Laden Captive! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...
- HDOJ 1085 Holding Bin-Laden Captive! (母函数)
Holding Bin-Laden Captive! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...
随机推荐
- python - 类的特殊成员
class Foo: #构造方法 def __init__(self,name,age): pass self.name = name self.age = age def __str__(self) ...
- 使用 Fluent API 配置/映射属性和类型2
1.将多个实体类映射到数据库中的一个表 要将多个实体映射到一个数据库表需要满足: a. 两个实体必须是一对一关系 b.两个实体共享一个主键 public class MyContext:DbConte ...
- 数据库分库分表(sharding)系列(一)拆分实施策略和示例演示
本文原文连接: http://blog.csdn.net/bluishglc/article/details/7696085 ,转载请注明出处!本文着重介绍sharding切分策略,如果你对数据库sh ...
- C#不用COM组件导出数据到Excel中
<?xml version='1.0'?><?mso-application progid='Excel.Sheet'?><Workbook xmlns='urn:sch ...
- NSSet使用小结
http://blog.csdn.net/ms2146/article/details/8657011
- SpringMVC中用@ParamVariable传递的参数包含斜杠(/)时,匹配不了报404错误的解决方案
今天做网站[标签]筛选功能时,出现了这么个奇葩的问题. 我是直接通过<a>标签中href来跳转的,url中包含汉字 <a href="/tags/标签A"> ...
- C#设置鼠标在控件上面时,改变光标形状
//设置鼠标在控件上面时,改变光标形状 private void pictureBox_macroLogo_MouseHover(object sender, System.EventArgs e) ...
- python中的 json 模块使用
(1)python 中生成 json 字符串: import json data = dict(ret=0, msg="Welcome, Login success!") json ...
- hadoop学习之hadoop完全分布式集群安装
注:本文的主要目的是为了记录自己的学习过程,也方便与大家做交流.转载请注明来自: http://blog.csdn.net/ab198604/article/details/8250461 要想深入的 ...
- /users/products.:format 这种写法的其对应解析字符写法
“products.:format" 这种写法可以有对应的下面两种路由形式 /products.json /products.xml "products.:format?" ...