AcWing 5. 多重背包问题 II
2021-01-29 04:13
阅读:587
标签:div names for 二进制优化 ret max namespace cin style
//二进制优化 最后变为01背包 #include#include using namespace std; const int N = 12010, M = 2010; int n, m; int v[N], w[N]; int f[M]; int main() { cin >> n >> m; int cnt = 0; for (int i = 1; i ) { int a, b, s; cin >> a >> b >> s; int k = 1; while (k s) { cnt ++ ; v[cnt] = a * k; w[cnt] = b * k; s -= k; k *= 2; } if (s > 0) { cnt ++ ; v[cnt] = a * s; w[cnt] = b * s; } } n = cnt; for (int i = 1; i ) for (int j = m; j >= v[i]; j -- ) f[j] = max(f[j], f[j - v[i]] + w[i]); cout endl; return 0; }
AcWing 5. 多重背包问题 II
标签:div names for 二进制优化 ret max namespace cin style
原文地址:https://www.cnblogs.com/QingyuYYYYY/p/11873181.html
文章来自:搜素材网的编程语言模块,转载请注明文章出处。
文章标题:AcWing 5. 多重背包问题 II
文章链接:http://soscw.com/index.php/essay/48516.html
文章标题:AcWing 5. 多重背包问题 II
文章链接:http://soscw.com/index.php/essay/48516.html
评论
亲,登录后才可以留言!