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
题目大意:给出三个数 num_1 , num_2 , num_5 , 分别表示有 num_1 个1元硬币,num_2 个2元硬币,num_5 个5元,求不能组成的最小的价值。
思路:母函数
虽然不是模板,只要改一改就好了。。。
附代码:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#define MAXN 10010
using namespace std;
int num1,num2,num3,n,s,a[MAXN],b[MAXN];
inline int read(){
int date=0,w=1;char c=0;
while(c<'0'||c>'9'){if(c=='-')w=-1;c=getchar();}
while(c>='0'&&c<='9'){date=date*10+c-'0';c=getchar();}
return date*w;
}
int main(){
while(1){
num1=read();num2=read();num3=read();
if(num1==0&&num2==0&&num3==0)break;
n=num1+(num2<<1)+(num3<<2)+num3;
memset(a,0,sizeof(a));memset(b,0,sizeof(b));
for(int i=0;i<=num1;i++)a[i]=1;
for(int i=0;i<=num1;i++)
for(int j=0;j<=(num2<<1);j+=2)
b[j+i]+=a[i];
for(int i=0;i<=num1+(num2<<1);i++){a[i]=b[i];b[i]=0;}
for(int i=0;i<=num1+(num2<<1);i++)
for(int j=0;j<=(num3<<2)+num3;j+=5)
b[j+i]+=a[i];
for(int i=0;i<=n;i++){a[i]=b[i];b[i]=0;}
for(s=0;s<=n;s++)if(a[s]==0)break;
printf("%d\n",s);
}
return 0;
}