题干:

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

题目大意:

给你cnt1个一元硬币,cnt2个两元硬币,cnt3个五元硬币,问不能凑出来的第一个面额是多少。

解题报告:

母函数。

AC代码:

#include<cstdio>
#include<queue>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int a[8005],b[8005];//b是中间值
int c[3];//1  2  5的数量
int d[3] = {1,2,5};
int n,m;
int main()
{int t;while(cin>>c[0]>>c[1]>>c[2]) {if(c[0] + c[1] + c[2] == 0) break;memset(a,0,sizeof a);memset(b,0,sizeof b);for(int i = 0; i<=c[0]; i++) {a[i]=1,b[i]=0;} int maxx = c[0] + c[1]*2 + c[2]*5;for(int i = 1; i<=2; i++) {for(int j = 0; j<=maxx; j++) {if(a[j]==0) continue;//剪枝 for(int k = 0; k<=c[i]; k++) {b[j+k*d[i]] += a[j];}}for(int j = 0; j<=maxx; j++) {a[j]=b[j];b[j]=0;}
//          for(int i = 0; i<=m; i++) printf("%d ",a[i]);
//          printf("\n");}int flag = 0;for(int i = 0; i<=maxx; i++) {if(a[i] == 0) {flag=1;printf("%d\n",i);break;}}if(flag ==0) printf("%d\n",maxx+1);}return 0;
}

稍微优化一点的代码:(但是还是15ms)

#include <iostream>
#include <cstring>
using namespace std;
int n[3],a[9000],b[9000],i,j,k,last,last2;
int v[3]={1,2,5};
int main()
{while ((cin>>n[0]>>n[1]>>n[2])&&(n[0]!=0||n[1]!=0|n[2]!=0)){a[0]=1;last=0;for (i=0;i<=2;i++){last2=last+n[i]*v[i];memset(b,0,sizeof(int)*(last2+1));for (j=0;j<=n[i];j++)for (k=0;k<=last;k++)b[k+j*v[i]]+=a[k];memcpy(a,b,sizeof(int)*(last2+1));last=last2;}for (i=0;i<=last;i++)if (a[i]==0)break;cout<<i<<endl;}return 0;
}

【HDU - 1085 】Holding Bin-Laden Captive! (母函数)相关推荐

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

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

  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!

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

  4. HDU 1085 Holding Bin-Laden Captive!

    这是拿三种不同的数量的硬币组合,然后你随便拿几个硬币组合,那么这就个硬币组合在一起的价值,不能等于某个数的最小值. 用母函数数感觉挺简单的,数组也不必开多大50就够了,其实可以更小.你想一下前面50都 ...

  5. hdu 1085 Holding Bin-Laden Capt

    给你a个1,b个2,c个5,问你不能组成的最小整数是多少 简单母函数,算了下复杂度,1秒足够 #include<iostream> #include<cstring> #def ...

  6. 母函数的初识——本拉登 hdu 1085

    题目链接 :母函数--本拉登 #include <iostream> #include <cstdio> #include <algorithm>using nam ...

  7. hdu 2065 红色病毒问题 (母函数)

    点击打开链接 指数型母函数问题 引例:假设有8个元素,其中a1重复3次, a2重复2次,a3重复3次.从中取r个组合,, 这样,对于一个多重集,其中a1重复n1次,a2 重复n2次,-,ak重复nk次 ...

  8. HDU - 1613 Ecological Bin Packing

    问题描述: Background Bin packing, or the placement of objects of certain weights into different bins sub ...

  9. 杭电OJ分类题目(1)

    原题出处:HDOJ Problem Index by Type,http://acm.hdu.edu.cn/typeclass.php 杭电OJ分类题目(1) HDU Introduction HDU ...

最新文章

  1. linux c 各头文件作用总结
  2. Codeforces 947E/923E Perpetual Subtraction (线性代数、矩阵对角化、DP)
  3. matlab输入集合,matlab关于集合的操作大全
  4. 2019.03.29 NOIP训练 友好国度(点分治+容斥)
  5. sed教程入门与实例练习(一)
  6. php rtc,php – webRTC与本地网络
  7. 外贸独立站VS第三方平台?
  8. C#中的委托和Java中的“委托”(Java8 lambda表达式)
  9. Python基本语法(一)
  10. 第3章 排列清单控制标记
  11. 全排列——深度优先搜索
  12. APP开发策划方案怎么写?
  13. php根据身份证号码确定地区(省份)地址
  14. 在虚拟机centos7中使用docker安装nginx后,本地浏览器无法访问?
  15. 结构光3D成像原理及应用
  16. Linux at命令使用介绍
  17. ios 关于开源框架GPUImage的简单说明
  18. matlab建立三层蒸发模型,水文模型三层蒸发模型的问题(初学者)
  19. Oracle Database Instant Client
  20. 关于因和数据库库断开数据源没有自动重连变无效的问题

热门文章

  1. ionic android 本地存储,ionic2/3本地数据存储storage
  2. linux系统访问文件夹ls,Linux系统目录结构,文件类型以及ls、alias命令
  3. python处理teradata数据库_Python脚本连接Teradata数据库
  4. java 析构函数_C++虚函数
  5. 英语答题测试的软件叫什么,英语做题软件哪个好 有答案解析的英语做题软件分享...
  6. x210-II WinCE启动10s,还可继续优化
  7. 210板wince键盘驱动分析和移植
  8. python database ioerror_python – IOError:[Errno 2]没有这样的文件或...
  9. c语言学习自我评价,学习自我评价4篇
  10. php vo 遍历,thinkPHP简单遍历数组方法分析