随笔分类 -  搜索与图论

摘要:DFS 剪枝 点击查看代码 #include<bits/stdc++.h> using namespace std; typedef long long LL; const int N = 1e6 + 10; int n; int w[N]; int sum, len; bool st[N]; bo 阅读全文
posted @ 2022-08-23 23:57 wKingYu 阅读(62) 评论(0) 推荐(0)
摘要:DFS + 剪枝 + 位运算优化 点击查看代码 #include<bits/stdc++.h> using namespace std; typedef long long LL; const int N = 9, M = 1 << N; int ones[M]; // ones[i]表示i的二进制 阅读全文
posted @ 2022-08-18 00:17 wKingYu 阅读(72) 评论(0) 推荐(0)
摘要:DFS 剪枝 点击查看代码 #include<bits/stdc++.h> using namespace std; typedef long long LL; const int N = 50 + 10; int n, m; int w[N]; int sum[N]; // 每组的重量之和 int 阅读全文
posted @ 2022-08-17 22:14 wKingYu 阅读(37) 评论(0) 推荐(0)
摘要:DFS 剪枝 点击查看代码 #include<bits/stdc++.h> using namespace std; typedef long long LL; const int N = 50 + 10; int n; int a[N]; int ans = 1e9; vector<int> g[ 阅读全文
posted @ 2022-08-17 17:50 wKingYu 阅读(44) 评论(0) 推荐(0)
摘要:DFS 点击查看代码 #include<bits/stdc++.h> using namespace std; typedef long long LL; const int N = 50 + 10; int n; string word[N]; int g[N][N]; // g[i][j]表示w 阅读全文
posted @ 2022-08-17 13:11 wKingYu 阅读(42) 评论(0) 推荐(0)
摘要:并查集 + 树的判定 点击查看代码 #include<bits/stdc++.h> using namespace std; typedef long long LL; const int N = 1e6 + 10; int n; int p[N]; int find(int x) { if (p[ 阅读全文
posted @ 2022-08-16 17:22 wKingYu 阅读(42) 评论(0) 推荐(0)
摘要:并查集 + 树的判定 点击查看代码 #include<bits/stdc++.h> using namespace std; typedef long long LL; const int N = 1e4 + 10; int n; int p[N]; int find(int x) { if (p[ 阅读全文
posted @ 2022-08-16 14:21 wKingYu 阅读(46) 评论(0) 推荐(0)
摘要:二分 + 双端队列广搜 复杂度 $m \cdot log(r - l) = 1 \times 10^4 \times log(10^9) = 3 \times 10^5$ 点击查看代码 #include<bits/stdc++.h> using namespace std; typedef long 阅读全文
posted @ 2022-08-10 23:44 wKingYu 阅读(41) 评论(0) 推荐(0)
摘要:最短路 + DFS 枚举顺序 最短路用堆优化 dijkstra 复杂度 $O(m \cdot log(n)) = 10^5 \cdot log(5 \times 10^4) \approx 1.56 \times 10^6$ DFS 枚举复杂度 $O(n!) = 5! = 120$ 两个复杂度是相加 阅读全文
posted @ 2022-08-10 22:29 wKingYu 阅读(57) 评论(0) 推荐(0)
摘要:三维迷宫 BFS + 结构体存储 点击查看代码 #include<bits/stdc++.h> using namespace std; typedef long long LL; const int N = 100 + 10; const int INF = 0x3f3f3f3f; int L, 阅读全文
posted @ 2022-08-10 13:35 wKingYu 阅读(51) 评论(0) 推荐(0)
摘要:八皇后问题的变形 $DFS$ 按行枚举 点击查看代码 #include<bits/stdc++.h> using namespace std; typedef long long LL; const int N = 10 + 10; int n, m; char g[N][N]; bool col[ 阅读全文
posted @ 2022-08-10 13:09 wKingYu 阅读(39) 评论(0) 推荐(0)
摘要:贪心 + 连通性 + 最短路 点击查看代码 #include<bits/stdc++.h> using namespace std; typedef long long LL; const int N = 100 + 10; const int INF = 0x3f3f3f3f; const int 阅读全文
posted @ 2022-08-09 23:56 wKingYu 阅读(47) 评论(0) 推荐(0)
摘要:建图 + 有限制的最短路 点击查看代码 #include<bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int,int> PII; const int N = 1e6 + 10; const int M 阅读全文
posted @ 2022-08-09 19:35 wKingYu 阅读(38) 评论(0) 推荐(0)
摘要:按照换乘次数建图,求单源最短路 点击查看代码 #include<bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int,int> PII; const int N = 1e6 + 10; const int 阅读全文
posted @ 2022-08-09 17:50 wKingYu 阅读(48) 评论(0) 推荐(0)
摘要:乘积最大的路径 堆优化 dijkstra 复杂度 $O(m \cdot log(n)) = 1 \times 10^5 \times log(2000) \approx 1.1 \times 10^6$ 点击查看代码 #include<bits/stdc++.h> using namespace s 阅读全文
posted @ 2022-08-09 11:52 wKingYu 阅读(33) 评论(0) 推荐(0)
摘要:选一个起点,到其他点的最短距离之和最小 堆优化 dijkstra ($2500 \ ms$) 复杂度 $O(m \cdot log(n) \cdot p) = 1450 \times log(500) \times 800 \approx 1.04 \times 10^7$ 点击查看代码 #incl 阅读全文
posted @ 2022-08-09 00:15 wKingYu 阅读(42) 评论(0) 推荐(0)
摘要:求起点到其他所有点的最短距离 堆优化 $dijkstra$ ($20 \ ms$) 复杂度 $(m \cdot log(n)) = 200 \times log(100) \approx 664$ 点击查看代码 #include<bits/stdc++.h> using namespace std; 阅读全文
posted @ 2022-08-08 23:18 wKingYu 阅读(46) 评论(0) 推荐(0)
摘要:起点到终点的最短距离 堆优化 dijkstra 复杂度 $O(m \cdot log(n)) = 6200 \times log(2500) \approx 7 \times 10^4$ 点击查看代码 #include<bits/stdc++.h> using namespace std; type 阅读全文
posted @ 2022-08-08 22:44 wKingYu 阅读(45) 评论(0) 推荐(0)
摘要:DFS 求方案个数 点击查看代码 #include<bits/stdc++.h> using namespace std; typedef long long LL; const int N = 100 + 10; int n, m, x, y; bool st[N][N]; int res; in 阅读全文
posted @ 2022-08-07 22:42 wKingYu 阅读(44) 评论(0) 推荐(0)
摘要:Flood Fill 的 DFS 写法 点击查看代码 #include<bits/stdc++.h> using namespace std; typedef long long LL; const int N = 100 + 10; int n, m; char g[N][N]; bool st[ 阅读全文
posted @ 2022-08-07 22:31 wKingYu 阅读(36) 评论(0) 推荐(0)