上一页 1 2 3 4 5 6 7 8 ··· 10 下一页
摘要: 注意1:严格递增 注意2:本身序列为1 注意3:倒着往回找的时候,每个都要试一下,不能提前剪枝 #include <bits/stdc++.h> using namespace std; int n; const int N=1010; int num[N]; int dp[N]; int main 阅读全文
posted @ 2026-03-12 01:05 peter_shen 阅读(6) 评论(0) 推荐(0)
摘要: 完全背包问题 但题目因为需要min,而我用-1来做标记,导致我得判断可不可行,无法压缩为一维dp数组,如果我用1e9做标记就可以了 #include <bits/stdc++.h> using namespace std; int n,m; const int N=510; int w[N]; in 阅读全文
posted @ 2026-03-12 00:23 peter_shen 阅读(7) 评论(0) 推荐(0)
摘要: 0-1 背包问题 #include <bits/stdc++.h> using namespace std; int n; const int N=1010; int price[N]; int dp[N]; int main(){ while(scanf("%d",&n)!=EOF){ for(i 阅读全文
posted @ 2026-03-11 22:41 peter_shen 阅读(11) 评论(0) 推荐(0)
摘要: 使用dfs来查找有几个连通子图,顺带着把每个连通子图是否为二分图也给判断了 #include <bits/stdc++.h> using namespace std; const int N=1e5+10; int n,m; //n为城市数,m为路数 vector<int> mp[N]; //存了边 阅读全文
posted @ 2026-03-11 21:13 peter_shen 阅读(9) 评论(0) 推荐(0)
摘要: ![image](https://img2024.cnblogs.com/blog/3767772/202603/3767772-20260311211154049-573051378.png) ![image](https://img2024.cnblogs.com/blog/3767772/202603/3767772-20260312210540644-1726894946.png) 阅读全文
posted @ 2026-03-11 21:12 peter_shen 阅读(5) 评论(0) 推荐(0)
摘要: BFS遍历节点,每次遍历一个节点的时候都去检验一下相连节点是否染色,若染色了,是否和自己不同 因为若一个图是二分图,那么所有点要么是黑色要么是白色,任意两个相同颜色的点在图中都一定是没有相连的 #include <bits/stdc++.h> using namespace std; const i 阅读全文
posted @ 2026-03-11 17:25 peter_shen 阅读(9) 评论(0) 推荐(0)
摘要: 拓扑排序 除了一开始靠fun1将入度为0的节点加入vec,之后都直接在fun2完成 #include <bits/stdc++.h> using namespace std; int n,m; const int N=510; vector<int> mp[N]; //邻接表 int rudu[N] 阅读全文
posted @ 2026-03-11 16:11 peter_shen 阅读(11) 评论(0) 推荐(0)
摘要: 数学上最小生成树的最大边一定是所有生成树中最大边的最小值 #include <bits/stdc++.h> using namespace std; int n; const int N=105; double x[N]; double y[N]; double cost[N]; double t; 阅读全文
posted @ 2026-03-11 00:51 peter_shen 阅读(8) 评论(0) 推荐(0)
摘要: 使用多源BFS, 注意1:方向数组别写错 注意2:kruskal算法要用并查集来维护 注意3:n个节点的最小生成树只需要找到n-1条边就可以了 #include<bits/stdc++.h> using namespace std; const int N=105; char mp[N][N]; i 阅读全文
posted @ 2026-03-11 00:48 peter_shen 阅读(9) 评论(0) 推荐(0)
摘要: 注意1: 1-2-3-4-5-2 这样的特殊的成环方式要思考一下怎么在5的时候结束 注意2:递归函数如果我在函数里对vis清空,会死循环。 注意3:m很大的话,叶子节点的a【i】会重复计入,所以应该要及时对叶子节点的a【i】清零 注意4:结果可能会是longlong #include <bits/s 阅读全文
posted @ 2026-03-10 20:53 peter_shen 阅读(5) 评论(0) 推荐(0)
上一页 1 2 3 4 5 6 7 8 ··· 10 下一页