hdu 1085 有num1个 1 ,num2个 2 ,num3个 5 (母函数)

时间:2021-01-31 11:01:08

有num1个 1 ,num2个 2 ,num3个 5
问它们不能组成的最小正整数是谁

样例的母函数 (1+X)(1+X2)(1+X5+X10+X15)
展开后 X4的系数为0


Sample Input
1 1 3
0 0 0

Sample Output
4

 

hdu 1085  有num1个 1 ,num2个 2 ,num3个 5  (母函数)hdu 1085  有num1个 1 ,num2个 2 ,num3个 5  (母函数)
 1 # include <iostream>
2 # include <cstdio>
3 # include <cstring>
4 # include <algorithm>
5 # include <string>
6 # include <cmath>
7 # include <queue>
8 # include <list>
9 # define LL long long
10 using namespace std ;
11
12
13 int c1[10010], c2[10010] ;
14 int w[4] = {0 , 1 , 2 , 5};
15 int num[5];
16
17 int main()
18 {
19 //freopen("in.txt","r",stdin) ;
20 int n ;
21 while(scanf("%d %d %d", &num[1], &num[2], &num[3])!= EOF )
22 {
23 if (num[1] == 0 && num[2] == 0 && num[3] == 0)
24 break ;
25 int Max = num[1]*w[1]+num[2]*w[2]+num[3]*w[3];
26
27 memset(c1, 0, sizeof(c1));
28 memset(c2, 0, sizeof(c2));
29 int i , j , k ;
30 for(i=0; i<=w[1]*num[1]; i+=w[1])
31 c1[i] = 1;
32 int len = w[1]*num[1];
33 for(i=2; i<=3; ++i)
34 {
35 for(j=0; j<=len; ++j)
36 for(k=0; k<=w[i]*num[i]; k+=w[i])
37 {
38 c2[k+j] += c1[j];
39 }
40 len += w[i]*num[i];
41 for(j=0; j<=len; ++j)
42 {
43 c1[j] = c2[j];
44 c2[j] = 0;
45 }
46 }
47 for(i=0; i<=Max; ++i)
48 if(c1[i] == 0)
49 {
50 printf("%d\n", i);
51 break;
52 }
53 if(i == Max+1)
54 printf("%d\n", i);
55 }
56 return 0;
57 }
View Code