【HDOJ】1248 寒冰王座
简单背包问题。水题。其实题目还可以不考虑350,因为350=200+150。
1 #include <stdio.h> 2 3 #define MAXNUM 10001 4 #define TOOLNUM 3 5 6 int prices[TOOLNUM] = {150,200,350}; // order asc 7 int left[MAXNUM]; 8 9 int main() { 10 int i, j, min; 11 int case_n, n; 12 13 for (i=0; i<MAXNUM; ++i) { 14 min = i; 15 for (j=0; j<TOOLNUM; ++j) { 16 if (i < prices[j]) 17 continue; 18 if (left[i-prices[j]] < min) 19 min = left[i-prices[j]]; 20 } 21 left[i] = min; 22 } 23 24 scanf("%d", &case_n); 25 26 while (case_n--) { 27 scanf("%d", &n); 28 printf("%d\n", left[n]); 29 } 30 31 return 0; 32 }