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三中硬币及其数量,问你用这些硬币不能组成的最小数字是多少。一开始没有思路,后来看了其他人的博客说用母函数,
大概看了一下母函数的,本人也是初学母函数,这题算是母函数入门题,比较简单,模拟多项式乘积就行,由于本人也是初学母函数,我在这就不介绍母函数了,
网上好多资料,我觉得杭电的ppt比较好。
三种硬币要组合起来可以看成是多项式相乘,比如一个价值为1的硬币和一个价值为2的硬币组合可以看成是(1+x)*(1+x^2)=1+x+x^2+x^3;
每一项的指数代表组合后的价值,系数表示组成该价值的方法数。关键在于如何模拟多项式相乘。
 1 #include <iostream>
 2 #include <cstring>
 3 using namespace std;
 4 
 5 int main()
 6 {
 7     int n,m,k,a1[11000],a2[11000],a3[11000],ma;
 8     while (cin>>n>>m>>k)
 9     {
10           if (n==0&&m==0&&k==0)
11           break;
12           memset(a1,0,sizeof(a1));
13           memset(a2,0,sizeof(a1));
14           memset(a3,0,sizeof(a1));
15           for (int i=0;i<=n;i++)
16           a1[i]=1;
17           
18           for (int j=0;j<=n;j++)
19           for (int i=0;i<=2*m;i+=2)
20           a2[j+i]+=a1[j];
21           
22           for (int i=0;i<=n+2*m;i++)
23           for (int j=0;j<=k*5;j+=5)
24           a3[i+j]+=a2[i];
25           
26           int t=0;
27           for (int i=0;i<=1100;i++)
28           {
29               if (a3[i]==0)
30               {
31                            t=1;
32                            cout <<i<<endl;
33                            break;
34               }
35           }
36           if (t==0)
37           {
38                    cout <<n+2*m+5*k+1<<endl;//这个地方要注意,所有的都有那就是n+2*m+5*k+1最小。
39           }
40     }
41     return 0;
42 }

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. HDU 1085 Holding Bin-Laden Captive!(母函数,或者找规律)

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

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

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

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

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

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

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

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

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

  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. JQuery实现倒计时效果

    首先:引入jquery文件 <script type="text/javascript" src="http://www.cnblogs.com/Content/P ...

  2. cocos2dx ——屏幕适配

    本文出自 “夏天的风” 博客,请务必保留此出处 http://shahdza.blog.51cto.com/2410787/1550089 手机的屏幕大小千差万别,如现在流行的安卓手机屏幕大部分长宽比 ...

  3. 微软企业库的Cache

    微软企业库的Cache 通常,应用程序可以将那些频繁访问的数据,以及那些需要大量处理时间来创建的数据存储在内存中,从而提高性能.基于微软的企业库,我们的快速创建一个缓存的实现. 新建PrismSamp ...

  4. iOS 证书与签名 解惑详解

    iOS 证书与签名 解惑详解 分类: iPhone2012-06-06 19:57 9426人阅读 评论(1) 收藏 举报 iosxcodecryptographyappleiphone测试   目录 ...

  5. 磁盘IO性能监控(Linux 和 Windows)

    磁盘IO性能监控(Linux 和 Windows) 作者:终南   <li.zhongnan@hotmail.com> 磁盘的IO性能是衡量计算机总体性能的一个重要指标.Linux提供了i ...

  6. 字符串转换为float<1>

    zjtest7-frontend:/usr/local/logstash-2.3.4/config# cat g01.conf input {stdin{}} filter { grok { matc ...

  7. Compound class names are not supported. Consider searching for one class name and filtering the results

    原文地址:http://stackoverflow.com/questions/20361643/compound-class-names-are-not-supported-consider-sea ...

  8. Eclipse + CDT + YAGARTO + J-Link,STM32开源开发环境搭建与调试

    Eclipse+CDT+YAGARTO+J-Li:开源开发环境搭建与调试:作者:Chongqing:邮箱:ycq.no1@163.com:文档版本:V1.0:发布日期:2014-08-04:前言:此文 ...

  9. 简单实用后台任务执行框架(Struts2+Spring+AJAX前端web界面可以获取进度)

    使用场景: 在平常web开发过程中,有时操作员要做一个后台会运行很长时间的任务(如上传一个大文件到后台处理),而此时前台页面仍需要给用户及时的进度信息反馈,同时还要避免前台页面超时. 框架介绍: 本架 ...

  10. 漏洞:WebRTC 泄漏用户IP

    WebRTC又称为“网页即时通信”,是一组API函数,它经过W3C组织的认证,支持浏览器之间的语音通话.视频聊天和P2P模式分享文件.      这个协议主要包括:getUserMedia,RTCPe ...