万变不离其中,只是我最后少考虑一种情况,如果i==num+1的情况!!!!!!!
http://acm.hdu.edu.cn/showproblem.php?pid=1085
View Code
1 #include<stdio.h> 2 3 #define max 80001 4 5 int main( ) 6 { 7 int i; 8 int j; 9 int c1[max]; 10 int c2[max]; 11 int num_1; 12 int num_2; 13 int num_3; 14 int num; 15 while( scanf("%d %d %d",&num_1,&num_2,&num_3),num_1,num_2,num_3 ) 16 { 17 18 num = num_1+num_2*2+num_3*5; 19 20 for( i = 0;i <= num; i++ ) 21 { 22 if( i <= num_1 ) 23 c1[i] = 1; 24 else 25 { 26 c1[i] = 0; 27 c2[i] = 0; 28 } 29 } 30 31 for( i = 0; i <= num_1; i++ ) 32 { 33 for ( j = 0; j <= num_2; j++ ) 34 { 35 c2[i+j*2] += c1[i]; 36 } 37 } 38 for( i = 0; i <= (num_1+num_2*2); i++) 39 { 40 c1[i] = c2[i]; 41 c2[i] = 0; 42 } 43 44 for( i = 0; i <= num_1+num_2*2; i++ ) 45 { 46 for ( j = 0; j <= num_3; j++ ) 47 { 48 c2[j*5+i] = c1[i]; 49 } 50 } 51 for( i = 0; i <= num; i++ ) 52 { 53 c1[i] = c2[i]; 54 c2[i] = 0; 55 } 56 57 for( i = 0;i <= num; i++ ) 58 { 59 if( c1[i] == 0 ) 60 { 61 printf("%d\n",i); 62 break; 63 } 64 } 65 if( i == num+1 ) 66 printf("%d\n",i); 67 } 68 return 0; 69 }