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

文章探讨了如何通过给定不同面额的硬币,计算使用这些硬币组合后无法支付的最小金额。通过解决Bin-Laden提出的数学问题,揭示了解决此类组合问题的方法。
部署运行你感兴趣的模型镜像

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!

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

Author
lcy
道题算是母函数当中比较简单的一道题,只要你能够求出所有的组合个数,就可以解出来,关于母函数的详解,请看这里:http://blog.youkuaiyun.com/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,否则为0
		memset(flag,0,sizeof(flag));//初始化,全部标为0
		memset(temp,0,sizeof(temp));
		for(i=0;i<=m;i++)  flag[i]=1;//先是1
		for(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;
}


您可能感兴趣的与本文相关的镜像

Stable-Diffusion-3.5

Stable-Diffusion-3.5

图片生成
Stable-Diffusion

Stable Diffusion 3.5 (SD 3.5) 是由 Stability AI 推出的新一代文本到图像生成模型,相比 3.0 版本,它提升了图像质量、运行速度和硬件效率

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值