2 380 200Example Output
30 0Hint
完全背包问题,注意与01背包问题的不同。
01 | #include<stdio.h> |
02 | #include<string.h> |
03 | int max( int a, int b) |
04 | { |
05 | return a > b? a : b; |
06 | } |
07 | int main() |
08 | { |
09 | int T, n, i, j, k; |
10 | int b[] = {150, 200, 350}; |
11 | int a[11111]; |
12 | scanf ( "%d" , &T); |
13 | for (k = 1; k <= T; k++) |
14 | { |
15 | memset (a, 0, sizeof (a)); |
16 | scanf ( "%d" , &n); |
17 | for (i = 0; i < 3; i++) |
18 | { |
19 | for (j = b[i]; j <= n; j++) |
20 | { |
21 | a[j] = max(a[j], a[j - b[i]] + b[i]); |
22 | } |
23 | } |
24 | printf ( "%d/n" , n - a[n]); |
25 | } |
26 | return 0; |
27 | } |
28 |
新闻热点
疑难解答