# hdu 1085 Holding Bin-Laden Captive! (母函数)

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 30 0 0

Sample Output
4

Author
lcy

Recommend
We have carefully selected several similar problems for you:  1171 2152 2082 1709 2079

0 :  c2[0]+=c1[0]         c2[0+(2*j)]+=c1[0]  .......

1 :  c2[1]+=c1[1]           c2[ 1+(2*j)] +=c1[0] ........

.......

a :.......................

0:     c2[0+(5*j)]+=c1[0] ......

..........

a+ 2*b  : ..........

#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<iostream>
#include<math.h>
#include<queue>
#include<map>
#include<vector>
#include<set>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
int c1[11330],c2[11330];
int num[5];
int a[12]={0,1,2,5};
int main()
{
int n;
while(~scanf("%d%d%d",&num[1],&num[2],&num[3])&&num[1]+num[2]+num[3])
{
memset(c2,0,sizeof(c2));
memset(c1,0,sizeof(c1));
for(int i=0;i<=num[1];i++)//1号元素
c1[i]=1;
int ans=num[1];
for(int i=2;i<=3;i++)//一共 3个元素
{
for(int j=0;j<=ans;j++) //到上一个元素能取得的最大值
{
for(int k=0;k<=num[i];k++) //当前元素的个数
{
c2[j+k*a[i]]+=c1[j];
}
}
ans+=num[i]*a[i]; //最大值改变
for(int j=0;j<=ans;j++) //c2赋给c1
c1[j]=c2[j];
memset(c2,0,sizeof(c2)); //c2 清空
}
int i;
for(i=0;i<11300;i++)
{
if(c1[i]==0)
{
printf("%d\n",i);
break;
}
}
}
}
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<iostream>
#include<math.h>
#include<queue>
#include<map>
#include<vector>
#include<set>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
int v[3511330];
int w[11];
int a[10]={0,1,2,5};
int main()
{
int yy=1;
while(~scanf("%d%d%d",&w[1],&w[2],&w[3])&&w[1]+w[2]+w[3])
{
int sum=0;
for(int i=1;i<=3;i++)
sum+=w[i]*a[i];
memset(v,0,sizeof(v));
v[0]=1;
for(int i=1;i<=3;i++)
{
for(int j=1;w[i];j=j<<1)
{
int u=a[i]*(j<=w[i]?j:w[i]);
for(int k=sum;k>=u;k--)
{
if(v[k-u]) v[k]=1;
}
if(j>w[i]) break;
w[i]-=j;
}
}
for(int i=1;i<=sum+1;i++)
{
if(v[i]==0)
{
printf("%d\n",i);
break;
}
}
}
}


• 评论

• 上一篇
• 下一篇