Holding Bin-Laden Captive!
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 17732 Accepted Submission(s): 7940
“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!
#include<stdio.h>
#include<string.h>
const int MAXN=;
int a[MAXN],b[MAXN];
int main(){
int x,y,z,sum;
int money[],t[];
while(scanf("%d%d%d",&x,&y,&z),x||y||z){
memset(a,,sizeof(a));memset(b,,sizeof(b));//初始化。。。
for(int i=;i<=x;i++)a[i]=,b[i]=;
t[]=x;t[]=y;t[]=z;
money[]=;money[]=;money[]=;
sum=money[]*t[];
for(int i=;i<;i++){
for(int j=;j<=sum;j++)
for(int k=;k<=money[i]*t[i];k+=money[i])
b[j+k]+=a[j];
sum+=money[i]*t[i];
for(int j=;j<=sum;j++)
a[j]=b[j];
}
//printf("%d\n",sum);
for(int i=;i<=sum+;i++)
if(!a[i]){
printf("%d\n",i);
break;
}
}
return ;
}
extern "C++"{
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;
const int INF = 0x3f3f3f3f;
#define mem(x,y) memset(x,y,sizeof(x))
typedef long long LL;
typedef unsigned long long ULL; void SI(int &x){scanf("%d",&x);}
void SI(double &x){scanf("%lf",&x);}
void SI(LL &x){scanf("%lld",&x);}
void SI(char *x){scanf("%s",x);} }
const int MAXN = ;
int a[MAXN],b[MAXN];
int num[];
int v[];
int main(){
while(~scanf("%d%d%d",&num[],&num[],&num[]),num[]|num[]|num[]){
mem(a,);mem(b,);
v[] = ;v[] = ;v[] = ;
int sum = ;
for(int i = ;i <= num[];i++)a[i] = v[],b[i] = ,sum += v[i] * num[i];
//int sum = num[0] * v[0];
for(int i = ;i <= ;i++){
for(int j = ;j <= sum;j++){
for(int k = ;k <= num[i];k++){
b[j + k * v[i] ] += a[j];
}
}
// sum += num[i] * v[i];
for(int j = ; j <= sum; j++)a[j] = b[j],b[j] = ;
}
int ans;
for(int i = ;i <= sum + ;i++){
if(a[i] == ){
ans = i;
break;
}
}
printf("%d\n",ans);
}
return ;
}