多学习。

随笔分类 -  动态规划

包括背包问题,线性DP,区间DP,计数类DP,数位统计DP,状态压缩DP,树形DP,记忆化搜索等内容。
摘要:AcWing282.石子合并 题解 #include <iostream> using namespace std; const int N = 310; int n, f[N][N], nums[N], s[N]; int main() { cin >> n; for(int i = 1; i < 阅读全文
posted @ 2022-06-15 22:13 czyaaa 阅读(32) 评论(0) 推荐(0) 编辑
摘要:AcWing896.最长上升子序列 II 题解 二分解法 q[i]保存长度为i的最小末尾,这样即可严格单调递增,从而对于每个新的数只要找出小于它的最大值就可算出长度 #include <cstdio> #include <iostream> using namespace std; const in 阅读全文
posted @ 2022-06-15 20:55 czyaaa 阅读(35) 评论(0) 推荐(0) 编辑
摘要:AcWing895.最长上升子序列 题解 #include <iostream> using namespace std; const int N = 1010; int f[N], nums[N]; int main() { int n, ans = 0; cin >> n; for(int i 阅读全文
posted @ 2022-06-14 22:31 czyaaa 阅读(19) 评论(0) 推荐(0) 编辑
摘要:AcWing898.数字三角形 题解 自底向上 #include <iostream> using namespace std; const int N = 510; int f[N][N]; int main() { int n; cin >> n; for(int i = 1; i <= n; 阅读全文
posted @ 2022-06-14 22:25 czyaaa 阅读(33) 评论(0) 推荐(0) 编辑
摘要:AcWing9.分组背包问题 题解 一维状压 #include <iostream> using namespace std; const int N = 110; int n, m, s[N], v[N][N], w[N][N], f[N]; int main() { cin >> n >> m; 阅读全文
posted @ 2022-06-14 09:36 czyaaa 阅读(16) 评论(0) 推荐(0) 编辑
摘要:AcWing5.多重背包问题 II 题解 #include <iostream> using namespace std; const int N = 20010, M = 2010; int v[N], w[N], cnt, n, m, f[M]; int main() { int a, b, c 阅读全文
posted @ 2022-06-14 09:05 czyaaa 阅读(19) 评论(0) 推荐(0) 编辑
摘要:AcWing4.多重背包问题 I 题解 状态分析与朴素完全背包问题相同。 不可如完全背包问题那样优化成二维循环:因为物品有个数限制 j - v的k和v的k不一定是一致的,例如:j-v → j-(s[i]+1) * v, j → j - s[i]*v #include <iostream> using 阅读全文
posted @ 2022-06-13 21:27 czyaaa 阅读(32) 评论(0) 推荐(0) 编辑
摘要:AcWing3.完全背包问题 题解 朴素写法 #include <iostream> using namespace std; const int N = 1010; int v[N], w[N]; int f[N][N]; int main() { int n, m; cin >> n >> m; 阅读全文
posted @ 2022-06-13 17:50 czyaaa 阅读(75) 评论(0) 推荐(0) 编辑
摘要:AcWing2.01背包问题 题解 二维 #include <iostream> using namespace std; const int N = 1010; int dp[N][N]; int v[N], w[N]; int main() { int n, V; cin >> n >> V; 阅读全文
posted @ 2022-06-13 16:53 czyaaa 阅读(21) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示