随笔分类 -  动态规划

摘要:点击查看代码 #include<iostream> using namespace std; const int N = 20; int n, a, b, c; int s[N][N]; int f[2 * N][N][N]; int main() { cin >> n; while (cin >> 阅读全文
posted @ 2022-06-15 23:58 wKingYu 阅读(25) 评论(0) 推荐(0) 编辑
摘要:点击查看代码 #include<iostream> using namespace std; const int N = 110; const int INF = 1e9; int n; int s[N][N], f[N][N]; int main() { cin >> n; for (int i 阅读全文
posted @ 2022-06-15 22:55 wKingYu 阅读(27) 评论(0) 推荐(0) 编辑
摘要:BFS + 动态规划 运行时间 855 ms 点击查看代码 #include<iostream> #include<cstring> #include<queue> #define fi first #define se second using namespace std; typedef pai 阅读全文
posted @ 2022-06-15 22:33 wKingYu 阅读(18) 评论(0) 推荐(0) 编辑
摘要:记忆化搜索 点击查看代码 #include<iostream> #include<cstring> using namespace std; const int N = 310; int n, m; int h[N][N]; int f[N][N]; int dx[4] = {-1, 0, 1, 0 阅读全文
posted @ 2022-06-03 21:09 wKingYu 阅读(20) 评论(0) 推荐(0) 编辑
摘要:点击查看代码 #include<iostream> #include<cstring> using namespace std; const int N = 6010; int n; int happy[N]; int h[N], e[N], ne[N], idx; bool has_father[ 阅读全文
posted @ 2022-06-03 12:27 wKingYu 阅读(20) 评论(0) 推荐(0) 编辑
摘要:位运算 + 状态压缩DP 点击查看代码 #include<iostream> #include<cstring> using namespace std; const int N = 20, M = 1 << 20; int n; int w[N][N]; int f[M][N]; int main 阅读全文
posted @ 2022-06-03 11:08 wKingYu 阅读(27) 评论(0) 推荐(0) 编辑
摘要:去除无效状态的优化写法 复杂度 O(n×2m×k) ( k 代表去处无效状态后的个数) 总体复杂度 <11×211×2114.6×107 点击查看代码 #includ 阅读全文
posted @ 2022-06-02 23:26 wKingYu 阅读(22) 评论(0) 推荐(0) 编辑
摘要:不使用 vector 的写法 点击查看代码 #include<iostream> #include<cmath> using namespace std; // 计算 n 有多少位 int dgt(int n) { int res = 0; while (n) { res ++; n /= 10; 阅读全文
posted @ 2022-05-25 09:40 wKingYu 阅读(19) 评论(0) 推荐(0) 编辑
摘要:类比完全背包 复杂度 O(n2) 总体复杂度 10002=1×106 点击查看代码 #include<iostream> using namespace std; const int N = 1010, mod = 1e9 + 7; int n; 阅读全文
posted @ 2022-05-24 20:44 wKingYu 阅读(25) 评论(0) 推荐(0) 编辑
摘要:复杂度 O(n3) 总体复杂度 3003=2.7×107 点击查看代码 #include<iostream> using namespace std; const int N = 300 + 10; int n; int s[N]; int f[N 阅读全文
posted @ 2022-05-24 20:10 wKingYu 阅读(30) 评论(0) 推荐(0) 编辑
摘要:复杂度 O(nml2) 总体复杂度 1000×1000×102=1×108 点击查看代码 #include<iostream> #include<cstring> using namespac 阅读全文
posted @ 2022-05-24 17:48 wKingYu 阅读(32) 评论(0) 推荐(0) 编辑
摘要:复杂度 O(n2) 总体复杂度 10002=1×106 点击查看代码 #include<iostream> using namespace std; const int N = 1010; int n, m; char a[N], b[N]; in 阅读全文
posted @ 2022-05-24 17:07 wKingYu 阅读(23) 评论(0) 推荐(0) 编辑
摘要:复杂度 O(nm) 总体复杂度 1000×1000=1×106 点击查看代码 #include<iostream> using namespace std; const int N = 1010; int n, m; char a[N] 阅读全文
posted @ 2022-05-23 21:07 wKingYu 阅读(29) 评论(0) 推荐(0) 编辑
摘要:线性 dp 复杂度 O(n2) 点击查看代码 #include<iostream> using namespace std; const int N = 1010; int n; int a[N], f[N]; int main() { cin >> n; for (int i = 0 阅读全文
posted @ 2022-05-23 18:01 wKingYu 阅读(23) 评论(0) 推荐(0) 编辑
摘要:使用一维数组优化 复杂度 n2 总体复杂度 5002=2.5×105 点击查看代码 #include<iostream> using namespace std; const int N = 510, INF = 1e9; int n; int a 阅读全文
posted @ 2022-05-20 18:28 wKingYu 阅读(15) 评论(0) 推荐(0) 编辑
摘要:点击查看代码 #include<iostream> using namespace std; const int N = 110; int n, m; int v[N][N], w[N][N], s[N]; int f[N]; int main() { cin >> n >> m; for (int 阅读全文
posted @ 2022-05-20 17:28 wKingYu 阅读(12) 评论(0) 推荐(0) 编辑
摘要:n,v,s 都较小 朴素写法 时间复杂度 n×v×s 总体复杂度 1003=1×106 点击查看代码 #include<iostream> using namespace std; const int N = 11 阅读全文
posted @ 2022-05-20 16:48 wKingYu 阅读(26) 评论(0) 推荐(0) 编辑
摘要:1. 朴素做法(会超时) 点击查看代码 #include<iostream> using namespace std; const int N = 1010; int n, m; int v[N], w[N]; int f[N][N]; int main() { cin >> n >> m; for 阅读全文
posted @ 2022-05-16 14:28 wKingYu 阅读(24) 评论(0) 推荐(0) 编辑
摘要:1. 朴素做法(二维数组) 点击查看代码 #include<iostream> using namespace std; const int N = 1010; int n, m; int v[N], w[N]; int f[N][N]; int main() { cin >> n >> m; fo 阅读全文
posted @ 2022-05-16 11:20 wKingYu 阅读(22) 评论(0) 推荐(0) 编辑

欢迎阅读『动态规划』
点击右上角即可分享
微信分享提示