【HDOJ】2191 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活
2014-04-28 14:02
288 查看
多重背包。
#include <stdio.h> #include <string.h> int ps, hs, cs, dp[105]; int n, m; void completePac(int p, int h) { int i, tmp; for (i=p; i<=n; ++i) { tmp = dp[i-p] + h; if (dp[i] < tmp) dp[i] = tmp; } } void onezeroPac(int p, int h) { int i, tmp; for (i=n; i>=p; --i) { tmp = dp[i-p] + h; if (dp[i] < tmp) dp[i] = tmp; } } void multiPac(int p, int h, int c) { int k; if (p*c >= n) { completePac(p, h); return ; } k = 1; while (k < c) { onezeroPac(k*p, k*h); c -= k; k *= 2; } if (c) onezeroPac(c*p, c*h); } int main() { int c; int i; scanf("%d", &c); while (c--) { scanf("%d %d", &n, &m); memset(dp, 0, sizeof(dp)); for (i=0; i<m; ++i) { scanf("%d %d %d", &ps, &hs, &cs); multiPac(ps, hs, cs); } printf("%d\n", dp ); } return 0; }
相关文章推荐
- HDOJ 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活 2191
- HDOJ-2191 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活
- HDOJ 2191 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活(完全背包)
- HDOJ-2191 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活
- hdoj 2191 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活 【多重背包 01背包】
- HDOJ 2191 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活(多重背包)
- hdoj-2191-悼念512汶川大地震遇难同胞——珍惜现在,感恩生活
- HDOJ 2191 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活 杭电 ACM
- HDOJ(HDU).2191. 悼念512汶川大地震遇难同胞――珍惜现在,感恩生活 (DP 多重背包+二进制优化)
- HDOJ 2191 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活(多重背包转换成0-1背包)
- HDOJ 2191 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活 (多重背包)
- [HDOJ] 2191 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活 [多重背包+二进制优化]
- hdoj 2191 (多维背包问题)悼念512汶川大地震遇难同胞——珍惜现在,感恩生活
- hdoj 2191 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活 【多重背包】【01-背包】
- HDOJ 题目2191 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活(多重背包问题)
- HDOJ 2191 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活(完全背包)
- 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活(hdoj--2191--多重背包)
- 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活(hdoj--2191--多重背包)
- hdoj 2191 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活(背包问题)
- hdoj 2191悼念512汶川大地震遇难同胞——珍惜现在,感恩生活【dp】