首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

杭电OJ——1085 Holding Bin-Laden Captive!(雌函数解答!)

2012-12-14 
杭电OJ——1085 Holding Bin-Laden Captive!(母函数解答!)Holding Bin-Laden Captive!Problem DescriptionWe

杭电OJ——1085 Holding Bin-Laden Captive!(母函数解答!)

Holding Bin-Laden Captive!

Problem DescriptionWe 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! ”

杭电OJ——1085 Holding Bin-Laden Captive!(雌函数解答!)


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!
 
InputInput 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.
 
OutputOutput 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
 
Authorlcy 这道题算是母函数当中比较简单的一道题,只要你能够求出所有的组合个数,就可以解出来,关于母函数的详解,请看这里: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;}


1楼wzllai3天前 09:29
杭电是什么?学校?
Re: lishuhuakai3天前 10:59
回复wzllain我靠,杭电都不知道!
Re: wzllai3天前 11:10
回复lishuhuakain知道 其实我就是杭电的。。。
Re: lishuhuakai3天前 11:11
回复wzllain那很好啊!杭电Oj真心不错的!
Re: wzllai3天前 11:13
回复lishuhuakain不错,有前途 我上线的时候就知道玩了
Re: lishuhuakai3天前 11:16
回复wzllain做题还挺有趣的,你们学校资源有那么好,可不要浪费了!

热点排行