Holding Bin-Laden Captive!(母函数)

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

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! ”

Holding Bin-Laden Captive!(母函数)

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
题解:money数组存的是面值,t数组存的是当前面值的个数
母函数为:
(1+x+x^2+x^3+.....+x^a)*(1+x^2+x^4+....+x^2b)*(1+x^5+x^10+...+x^5c);
代码:
 #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 ;
}
上一篇:利用JS去做响应式布局


下一篇:放球游戏B