problem Description
We all know this bin-laden is a notorious terrorist, and he has
Disappeared for a long time. But recently, it's reported that he
Hides in hang Zhou of china! "Oh, god! How terrible! ”
Don ' t is 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 to some math problems, and he said that if anyone can solve
His problem, he'll give himself up! ha-ha! Obviously, Laden is too
Proud of his intelligence! But, what's his problem? "Given Some
Chinese Coins (Coin) (three kinds–1, 2, 5), and their number is num_1,
Num_2 and num_5 respectively, please output the minimum value
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 are not
Processed. Output
Output the minimum positive value, one cannot pay with given
Coins, one line for one case. Sample Input
1 1 3
0 0 0
Sample Output
4
Ideas
Now there are several pieces of coins of $1, $2 and $5, asking what the minimum amount of these coins cannot be.
To apply a parent function, such as a coin with a sample value of 1,2,5, there are 1,1,3 pieces, then the expansion is:
(1+x) ∗ (1+x2) + (1+x5+x10+x15) (1 + x) ∗ (1 + x 2) + (1 + x 5 + x + x) (1+x) * (1+x^2) + (1+x^5+x^{10}+x^{15})
After this equation is unfolded, the exponent of the first non-existent coefficient item is the answer code 1 .
#include <cstdio> #include <cstring> #include <cctype> #include <stdlib.h> #include <string&
Gt #include <map> #include <iostream> #include <stack> #include <cmath> #include <queue> #
Include <vector> #include <algorithm> using namespace std;
typedef long Long LL;
#define INF 1000000 #define MEM (A, B) memset (A,b,sizeof (a)) const int n=8000+7;
int c1[n],c2[n],num[n];
int v[4]= {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]) {int n=num[1]*1+num[
2]*2+num[3]*5;
MEM (c1,0);
C1[0]=1;
for (int i=1; i<=3; i++) {mem (c2,0);
for (int j=0; j<=num[i]; j + +) for (int k=0; k+j*v[i]<=n; k++) c2[k+j*v[i]]+=c1[k];
memcpy (c1,c2,sizeof (C2));
} int ans=0;
while (C1[ans]) ans++;
printf ("%d\n", ans); } RetuRN 0;
}
Code 2
#include <cstdio> #include <cstring> #include <cctype> #include <stdlib.h> #include <string&
Gt #include <map> #include <iostream> #include <stack> #include <cmath> #include <queue> #
Include <vector> #include <algorithm> using namespace std;
typedef long Long LL;
#define INF 1000000 #define MEM (A, B) memset (A,b,sizeof (a)) const int n=1000+7;
int w[4]= {0,1,2,5};
int n[4],a[8005],b[8005],ans,lst;
void init () {mem (a,0);
A[0]=1;
lst=0; for (int k=1; k<=3; k++) {lst+=w[k-1]*n[k-1];//to find the highest number of times for (int i=0; i<=lst; i++) for ( int j=0; j<=n[k];
J + +) B[i+j*w[k]]+=a[i];
memcpy (A,b,sizeof (a));
MEM (b,0);
}} int main () {while (scanf ("%d%d%d", &n[1],&n[2],&n[3]) &&n[1]+n[2]+n[3]) {init ();
ans=0;
while (A[ans]) ans++;
printf ("%d\n", ans);
} return 0;
}