随笔分类 -  dp -- 背包

摘要:https://www.acwing.com/problem/content/1015/ 由dp输出方案 分组背包 #include <bits/stdc++.h> using namespace std; #define IO ios::sync_with_stdio(false);cin.tie 阅读全文
posted @ 2021-04-13 20:31 phr2000 阅读(46) 评论(0) 推荐(0)
摘要:f[i][j]: 表示氧气至少为i,氮气至少为j至少需要的重量. f[j][k] = min(f[j][k], f[max(0, j - a)][max(0, k - b)] + w); 由实际意义出发 : 如果a > j或b > k也是需要转移过来的. 如果这里不转移, f[i][j]的意义就变了 阅读全文
posted @ 2021-04-13 19:54 phr2000 阅读(51) 评论(0) 推荐(0)
摘要:https://www.acwing.com/problem/content/7/ 混合背包 多重背包用二进制优化. #include <bits/stdc++.h> using namespace std; #define IO ios::sync_with_stdio(false);cin.ti 阅读全文
posted @ 2021-04-13 19:15 phr2000 阅读(65) 评论(0) 推荐(0)
摘要:https://www.acwing.com/problem/content/280/ \(完全背包变式\) 01背包变式 #include <bits/stdc++.h> using namespace std; #define IO ios::sync_with_stdio(false);cin 阅读全文
posted @ 2021-04-12 21:41 phr2000 阅读(39) 评论(0) 推荐(0)
摘要:https://www.acwing.com/problem/content/280/ \(01背包变式\) \(f[i][j]:表示在前i个中选,选出的数和为j的个数.\) for (int i = 1; i <= n; ++i) f[i][0] = 1; for (int i = 1; i <= 阅读全文
posted @ 2021-04-12 21:21 phr2000 阅读(109) 评论(0) 推荐(0)
摘要:https://www.acwing.com/problem/content/1024/ 二维01背包 #include <bits/stdc++.h> using namespace std; #define IO ios::sync_with_stdio(false);cin.tie(0); c 阅读全文
posted @ 2021-04-12 19:54 phr2000 阅读(55) 评论(0) 推荐(0)