HDU 1248 完全背包问题 寒冰王座
View Code
1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<string.h> 4 #define N 10001 5 6 int f[N], value[3]; 7 int main() 8 { 9 int i, j, V, ncases; 10 11 scanf("%d", &ncases); 12 while( ncases-- ) 13 { 14 scanf("%d",&V); 15 value[0] = 150; 16 value[1] = 200; 17 value[2] = 350; 18 19 memset(f,0,sizeof(f)); 20 for(i=0; i<3; i++) 21 for(j=value[i]; j<=V; j++) 22 { 23 if(f[j] < f[j-value[i]]+value[i]) 24 f[j] = f[j-value[i]]+value[i]; 25 } 26 27 printf("%d\n",V-f[V]); 28 } 29 return 0; 30 }