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. js_day8

  2. CentOS 恢复 rm -rf * 误删数据(转)

    一. 将磁盘分区挂载为只读 这一步很重要,并且在误删除文件后应尽快将磁盘挂载为只读.越早进行,恢复的成功机率就越大. 1.  查看被删除文件位于哪个分区 [root@localhost  ~]# mo ...

  3. ASP.net button类控件click事件中传递参数

    单击Button会同时触发这两个事件,但先执行Click,后执行Command,在button控件中加上参数属性 CommandArgument='' 在click响应函数中可以用以下代码获得传递的参 ...

  4. Property与Attribute的区别

    Property属于面向对象的范畴----属性 Attribute则是编程语言文法层面的东西----特征          Property属于面向对象的范畴.在使用面向对象编程的时候,常常需要对客观 ...

  5. int.Tryparse() 、int.parse()、Convert.To32() 的区别

    int.Tryparse()  Int32.TryParse(source, result)则无论如何都不抛出异常,只会返回true或false来说明解析是否成功,如果解析失败,调用方将会得到0值. ...

  6. 7 RandomAccessFile读取文件内容保存--简单例子(需要验证)

    import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.*; /** * 读取动态产生的文件内容 */ publ ...

  7. java运算

    (一) 截图: 程序: import javax.swing.JOptionPane; public class Addition { public static void main (String ...

  8. poj3614 贪心

    Sunscreen Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6410   Accepted: 2239 Descrip ...

  9. hdu 1215 七夕节

    Problem Description 七夕节那天,月老来到数字王国,他在城门上贴了一张告示,并且和数字王国的人们说:"你们想知道你们的另一半是谁吗?那就按照告示上的方法去找吧!" ...

  10. SpringSource Tools Suite 字体偏小问题

    参照了Eclipse小技巧收录http://liuzidong.iteye.com/blog/1320094 发现没有找到相应文件,只有搜索了,一个一个地找,总算找到了,修改方法还是一样,只是路径,文 ...