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 3 0 0 0
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 8050
#define ms(a) memset(a,0,sizeof(a))
int price[3]={1,2,5};//存货币各种的价值;
int num[3];//存每种货币的数量 ;
int f[N],tem[N];//数组f1表示第i种货币有f[i]种表示方法;数组tem 为存临时变量
int main(){
while(cin>>num[0]>>num[1]>>num[2]&&num[0]+num[1]+num[2]){
int len=num[0]*price[0];//len是用来表示数组f的下界
ms(f);ms(tem);
for(int i=0;i<=len;i++){
f[i]=1;//初始化数组f
}
for(int i=1;i<3;i++){//是对货币种类的循环
len+=num[i]*price[i];//数组f下界的更新
for(int j=0;j<=len-num[i]*price[i];j++){//是对数组f的循环 ,len-num[i]*price[i]是表示上一种货币循环后数组f的下界
for(int k=0;k<=num[i]&&k*price[i]+j<=len;k++){//是对货币各种数量的循环
tem[j+k*price[i]]+=f[j];
}
}
for(int j=0;j<=len;j++){
f[j]=tem[j];
tem[j]=0;
}
}
for(int i=0;i<N;i++){
if(f[i]==0){
cout<<i<<endl;
break;
}
}
}
return 0;
}
用的男票写给我的模板
点击打开链接