随笔分类 - 动态规划
摘要:点击查看代码 #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 >>
阅读全文
摘要:点击查看代码 #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
阅读全文
摘要:BFS + 动态规划 运行时间 855 ms 点击查看代码 #include<iostream> #include<cstring> #include<queue> #define fi first #define se second using namespace std; typedef pai
阅读全文
摘要:记忆化搜索 点击查看代码 #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
阅读全文
摘要:点击查看代码 #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[
阅读全文
摘要:位运算 + 状态压缩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
阅读全文
摘要:不使用 vector 的写法 点击查看代码 #include<iostream> #include<cmath> using namespace std; // 计算 n 有多少位 int dgt(int n) { int res = 0; while (n) { res ++; n /= 10;
阅读全文
摘要:类比完全背包 复杂度 总体复杂度 点击查看代码 #include<iostream> using namespace std; const int N = 1010, mod = 1e9 + 7; int n;
阅读全文
摘要:复杂度 总体复杂度 点击查看代码 #include<iostream> using namespace std; const int N = 300 + 10; int n; int s[N]; int f[N
阅读全文
摘要:复杂度 总体复杂度 点击查看代码 #include<iostream> using namespace std; const int N = 1010; int n, m; char a[N], b[N]; in
阅读全文
摘要:复杂度 总体复杂度 点击查看代码 #include<iostream> using namespace std; const int N = 1010; int n, m; char a[N]
阅读全文
摘要:线性 dp 复杂度 点击查看代码 #include<iostream> using namespace std; const int N = 1010; int n; int a[N], f[N]; int main() { cin >> n; for (int i = 0
阅读全文
摘要:使用一维数组优化 复杂度 总体复杂度 点击查看代码 #include<iostream> using namespace std; const int N = 510, INF = 1e9; int n; int a
阅读全文
摘要:点击查看代码 #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
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文