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

Problem Description
We all know that Bin-Laden is a notorious terrorist, and he has disappeared for a long time. But recently, it is reported that he hides in Hang Zhou of China! 

“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!
 
Input
Input contains multiple test cases. Each test case contains 3 positive integers num_1, num_2 and num_5 (0<=num_i<=1000). A test case containing 0 0 0 terminates the input and this test case is not to be processed.
 
Output
Output the minimum positive value that one cannot pay with given coins, one line for one case.
 
Sample Input
1 1 3
0 0 0
 
Sample Output
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! (母函数)的更多相关文章

  1. HDU 1085 Holding Bin-Laden Captive!(母函数,或者找规律)

    Holding Bin-Laden Captive! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Ja ...

  2. HDOJ/HDU 1085 Holding Bin-Laden Captive!(非母函数求解)

    Problem Description We all know that Bin-Laden is a notorious terrorist, and he has disappeared for ...

  3. HDU 1085 Holding Bin-Laden Captive! 活捉本拉登(普通型母函数)

    题意: 有面值分别为1.2.5的硬币,分别有num_1.num_2.num_5个,问不能组成的最小面值是多少?(0<=每种硬币个数<=1000,组成的面值>0) 思路: 母函数解决. ...

  4. 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), //展 ...

  5. 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, ...

  6. hdu 1085 Holding Bin-Laden Captive!

    Problem Description We all know that Bin-Laden is a notorious terrorist, and he has disappeared for ...

  7. HDU 1085 Holding Bin-Laden Captive --生成函数第一题

    生成函数题. 题意:有币值1,2,5的硬币若干,问你最小的不能组成的币值为多少. 解法:写出生成函数: 然后求每项的系数即可. 因为三种硬币最多1000枚,1*1000+2*1000+5*1000=8 ...

  8. hdu 1085 给出数量限制的母函数问题 Holding Bin-Laden Captive!

    Holding Bin-Laden Captive! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Ja ...

  9. HDOJ 1085 Holding Bin-Laden Captive! (母函数)

    Holding Bin-Laden Captive! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Ja ...

随机推荐

  1. CentOS6.6(单用户模式)重设root密码

    1.开机时手要快按任意键,因为默认时间5s 2.grub菜单,只有一个内核,没什么好上下选的,按e键.不过如果你升级了系统或安装了Xen虚拟化后,就会有多个显示了. 3.接下来显示如下,选择第二项,按 ...

  2. (转)HTTP 无法注册 URL http://+:9999/CalculatorService/。进程不具有此命名空间的访问权限

    写WCF时在 1 host.Open(); 报错:HTTP 无法注册 URL http://+:9999/CalculatorService/.进程不具有此命名空间的访问权限(有关详细信息,请参见 h ...

  3. OpenGL ES 2.0 符点精度

    片元着色器中使用符点相关类型的变量时与顶点着色器中有所不同,在顶点着色器中直接声明使用即可,而在片元着色器中必须指定精度. lowp 低 mediump 中 highp 高 指定整个着色器中符点相关类 ...

  4. 【6】Laravel5.1的migration数据库迁移

    查看Laravel5.1的目录 当你配置好数据库后,在命令行执行下边的操作 php artisan migrate 打开数据库会发现,我们的数据库多了四个表,神奇吧! 打开任意一个migration查 ...

  5. dynamic和object浅谈

    要想知道dynamic和object的关系必须先理解它们的含义 C# 4.0提供了一个dynamic 关键字.在MSDN里是这样描述:在通过 dynamic 类型实现的操作中,该类型的作用是绕过编译时 ...

  6. Win7中,取消共享文件夹后有个小锁

    用过windows7的朋友都知道,Windows 7 中设置某一个文件夹属性为共享后,文件夹的图标上就增加一个小锁图案.起到了一个标记作用,挺好的.但是即使你将该文件夹的共享功能取消后,该小锁图案还是 ...

  7. 调查程序phpquestionnaire 2.2中文安装注意

    最近找调查投票软件 找到limesurvey 和 phpquestionnaire,limesurvey 中文可以用,但是比较烦琐.phpquestionnaire有汉化过的包下载,但是安装完,发现中 ...

  8. php性能效率优化

    [size=5][color=Red]php性能效率优化[/color][/size] 最近在公司一边自学一边写PHP程序,由于公司对程序的运行效率要求很高,而自己又是个新手,一开始就注意程序的效率很 ...

  9. Hdu1093

    #include <stdio.h> int main() { int T,n; ; while(scanf("%d",&T)!=EOF){ while(sca ...

  10. linux配置备忘

    ubuntu英文系统环境下,emacs输入中文设置:(http://www.cnblogs.com/pylemon/archive/2012/01/05/2312682.html) ~/.profil ...