有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
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 int c1[10010], c2[10010] ; 13 int num[5] ; 14 int main() 15 { 16 17 while(scanf("%d %d %d", &num[1], &num[2], &num[3])!= EOF ) 18 { 19 if (num[1] == 0 && num[2] == 0 && num[3] == 0) 20 break ; 21 int Max = num[1]*1+num[2]*2+num[3]*5; 22 23 for(int i=0; i<=Max; ++i) 24 { 25 c1[i] = 0; 26 c2[i] = 0; 27 } 28 for(int i=0; i<=num[1]; ++i) 29 c1[i] = 1; 30 for(int i=0; i<=num[1]; ++i) 31 for(int j=0; j<=num[2]*2; j+=2) 32 c2[j+i] += c1[i]; 33 for(int i=0; i<=num[2]*2+num[1]*1; ++i) 34 { 35 c1[i] = c2[i]; 36 c2[i] = 0; 37 } 38 39 for(int i=0; i<=num[1]*1+num[2]*2; ++i) 40 for(int j=0; j<=num[3]*5; j+=5) 41 c2[j+i] += c1[i]; 42 for(int i=0; i<=num[2]*2+num[1]*1+num[3]*5; ++i) 43 { 44 c1[i] = c2[i]; 45 c2[i] = 0; 46 } 47 int i; 48 49 for(i=0; i<=Max; ++i) 50 if(c1[i] == 0) 51 { 52 printf("%d\n", i); 53 break; 54 } 55 if(i == Max+1) 56 printf("%d\n", i); 57 } 58 return 0; 59 }
时间: 2024-10-02 20:17:18