杭电OJ——1085 Holding Bin-Laden Captive!(母函数解答!)
来源:互联网 发布:kindle usb网络 编辑:程序博客网 时间:2024/04/29 21:42
Holding Bin-Laden Captive!
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!
“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 30 0 0
Sample Output
4
Author
lcy
这道题算是母函数当中比较简单的一道题,只要你能够求出所有的组合个数,就可以解出来,关于母函数的详解,请看这里:http://blog.csdn.net/lishuhuakai/article/details/8044431
发代码吧!
//母函数问题,整数的拆分//以前做过这一类的题,现在回顾一下//我靠,这道题貌似比以前做的母函数的题目还要简单//只要求出有多少种组合方案就可以了//以下的两种方法皆可以做!/*#include<iostream>using namespace std;int main(){int n,m,j,i,k;while(cin>>m>>n>>k &&( m!=0 || n!=0 || k!=0)){int flag[10001],temp[10001];//用于标志可不可以组合,如果可以组合出i,则flag[i]=1,否则为0memset(flag,0,sizeof(flag));//初始化,全部标为0memset(temp,0,sizeof(temp));for(i=0;i<=m;i++) flag[i]=1;//先是1for(i=0;i<=n*2;i=i+2)//再2{for(j=0;j<=m;j++)temp[i+j]=1;}for(i=0;i<=m+2*n;i++)if(temp[i]==1)flag[i]=1;memset(temp,0,sizeof(temp));for(i=0;i<=k*5;i=i+5)//再5{for(j=0;j<=m+2*n;j++)if(flag[j]==1)temp[i+j]=1;}for(i=0;i<=m+2*n+5*k;i++)if(temp[i]==1)flag[i]=1;for(i=0;i<=2*n+m+5*k;i++){if(flag[i]==0)break;}cout<<i<<endl;}return 0;}*/#include<iostream>using namespace std;const int lmax=10000;int c1[lmax+1],c2[lmax+1];int main(){int n,m,k,i,j;while(cin>>m>>n>>k && (m!=0 || n!=0 || k!=0)){int sum=m+2*n+5*k;for(i=0;i<=sum;i++){c1[i]=0;c2[i]=0;}for(i=0;i<=m;i++) c1[i]=1;for(i=0;i<=m;i++)for(j=0;j<=2*n;j=j+2)c2[i+j]+=c1[i]; for(j=0;j<=sum;j++){c1[j]=c2[j];c2[j]=0;}for(i=0;i<=m+2*n;i++)for(j=0;j<=k*5;j=j+5) c2[j+i]+=c1[i]; for(j=0;j<=sum;j++){c1[j]=c2[j];c2[j]=0;} for(i=0;i<=sum;i++) { if(c1[i]==0) {printf("%d\n",i);break;} } if(i==sum+1) printf("%d\n",i); }return 0;}
- 杭电OJ——1085 Holding Bin-Laden Captive!(母函数解答!)
- 杭电acm1085.Holding Bin-Laden Captive!(母函数)
- [母函数]HDU 1085——Holding Bin-Laden Captive!
- Holding Bin-Laden Captive!(hdu1085)——母函数
- 杭电(1085)Holding Bin-Laden Captive!
- Holding Bin-Laden Captive!(杭电1085)(母函数)
- 杭电ACM hdu 1085 Holding Bin-Laden Captive! 解题报告(母函数)
- 杭电ACM 1085 Holding Bin-Laden Captive!(母函数)
- Holding Bin-Laden Captive! 1085 (母函数)
- Holding Bin-Laden Captive!(母函数)
- Holding Bin-Laden Captive!(母函数)
- Holding Bin-Laden Captive!(母函数)
- Holding Bin-Laden Captive!(母函数)
- Holding Bin-Laden Captive!(母函数)
- HDU 1085 Holding Bin-Laden Captive!(母函数)
- hdoj 1085 Holding Bin-Laden Captive!(母函数)
- hdu 1085 Holding Bin-Laden Captive! (母函数)
- HDU 1085 Holding Bin-Laden Captive! (母函数)
- 分页封装源代码
- Http和Socket区别
- CrashBalloon_1003
- 报表攻坚
- mysql大复习
- 杭电OJ——1085 Holding Bin-Laden Captive!(母函数解答!)
- make clean和 make distclean的区别
- 关于Java的String类型
- 2012-12-07股市集结号【创赢操盘】周五策略
- 循环与递归--不使用if,while,for,do—while语句来输出所有比已知数N小的自然数
- Mysql数据库常用命令
- 数据导出mongoexport和数据导入mongoimport
- Windows Server 2008 R2 中文版 实现两个用户同时登陆
- 电脑故障处理之手机般嗡嗡的响