hdu 1085 Holding Bin-Laden Captive!
Problem Description
“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三中硬币及其数量,问你用这些硬币不能组成的最小数字是多少。一开始没有思路,后来看了其他人的博客说用母函数,大概看了一下母函数的,本人也是初学母函数,这题算是母函数入门题,比较简单,模拟多项式乘积就行,由于本人也是初学母函数,我在这就不介绍母函数了,网上好多资料,我觉得杭电的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!的更多相关文章
- HDU 1085 Holding Bin-Laden Captive! (母函数)
Holding Bin-Laden Captive! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...
- HDU 1085 Holding Bin-Laden Captive!(母函数,或者找规律)
Holding Bin-Laden Captive! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...
- 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, ...
- 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的硬币若干,问你最小的不能组成的币值为多少. 解法:写出生成函数: 然后求每项的系数即可. 因为三种硬币最多1000枚,1*1000+2*1000+5*1000=8 ...
- 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!
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 ...
随机推荐
- rr
times = gcd(rotdist,length); printf( ;i<times;i++) { t = vec[i]; j = i; ) { k = j+ r ...
- No1_8.类和对象2_Java学习笔记_对象
对象 /**** * *一.对象 *1.概念:对象是由类抽象出来的,对象可以操作类的属性和方法解决问题,了解对象的创建.操作和消亡很必要: *2.对象的创建: * a. new操作符创建:每实例化一个 ...
- 【转】10 个迅速提升你 Git 水平的提示
最近我们推出了两个教程:熟悉Git的基本功能和让你在开发团队中熟练的使用Git . 我们所讨论的命令足够一个开发者在Git使用方面游刃有余.在这篇文章中,我们试图探索怎样有效的管理你的时间和充分的使用 ...
- javascript中定义事件的三种方式
在javascript中,可以为某个元素指定事件,指定的方式有以下三种: 1.在html中,使用onclick属性 2.在javascript中,使用onclick属性 3.在javascipt中,使 ...
- 高效的jQuery代码编写技巧总结
最近写了很多的js,虽然效果都实现了,但是总感觉自己写的js在性能上还能有很大的提升.本文我计划总结一些网上找的和我本人的一些建议,来提升你的jQuery和javascript代码.好的代码会带来速度 ...
- Failed to collect certificates from /data/app/vmdl201020547.tmp/base.apk: META-INF/CERT.SF indicates /data/app/vmdl201020547.tmp/base.apk is signed using APK Signature Scheme v2, but no such signature
错误信息: 12-26 11:08:44.809 1501-1535/system_process E/PackageInstaller: Commit of session 201020547 fa ...
- 基于cygwin构建u-boot(四)libgcc引用
接上文,config.mk文件修改后,即使没有.depend也可以正常处理了: 六.错误:gcclib引用错误 完成之前几篇的工作后,程序就可以一直执行了,直到最后生成u-boot, 出现如下错误告警 ...
- JAVA语言对比C++语言的几个优点和自身的关键特性
之所以写这篇博客不是为了比较JAVA语言和C++语言到底孰优孰劣,而是从语言本身出发进行对比总结程序编码设计上的差别.因水平有限,某些内容可能太过片面,欢迎指正和讨论. JAVA语言在设计上很好地借鉴 ...
- nodejs应用mysql(纯属翻译)
原文点击这里 目录 Install Introduction Contributors Sponsors Community Establishing connections Connection o ...
- .NET抽象工厂模式微理解--教你在项目中实现抽象工厂
.NET抽象工厂模式微理解--教你在项目中实现抽象工厂 最近在学习MVC,对于MVC里面的一些项目上的东西都和抽象模式有关,今天就微说明一下个人对于抽象工厂模式的理解,以方便学习MVC及工厂模式相关的 ...