上一页 1 2 3 4 5 6 7 ··· 10 下一页
摘要: dijkstra 轮询M次, floyd会超时 #include<bits/stdc++.h> using namespace std; int n; const int N=1005; double w[N][N]; double dist[N][N]; int vis[N]; struct cm 阅读全文
posted @ 2026-03-14 14:13 peter_shen 阅读(7) 评论(0) 推荐(0)
摘要: 非常好!非递归(迭代)版本的 DFS 和 BFS 不仅避免了递归栈溢出风险,还更容易控制流程。下面分别给出 非递归 DFS 和 BFS 检测环 的完整实现(支持 无向图 和 有向图)。 ✅ 一、无向图中检测环(非递归) 核心思想: 使用栈(DFS)或队列(BFS) 记录每个节点的 父节点(paren 阅读全文
posted @ 2026-03-14 00:38 peter_shen 阅读(14) 评论(0) 推荐(0)
摘要: 使用了dp,dp【i】保存了1-i,我能找到的最好情况。 #include <bits/stdc++.h> using namespace std; struct node{ int ans; int l; int r; bool operator==(const node& a)const{ if 阅读全文
posted @ 2026-03-13 22:36 peter_shen 阅读(8) 评论(0) 推荐(0)
摘要: 使用getline(cin,s)对string读空格 #include <bits/stdc++.h> using namespace std; int main(){ string s; while(getline(cin,s)){ if(s!="START") break; string t; 阅读全文
posted @ 2026-03-13 20:32 peter_shen 阅读(8) 评论(0) 推荐(0)
摘要: 使用kruskal写最小生成树 #include <bits/stdc++.h> using namespace std; const int M=105; const int N=5005; struct node{ int s; int t; int w; bool operator<(cons 阅读全文
posted @ 2026-03-13 16:39 peter_shen 阅读(8) 评论(0) 推荐(0)
摘要: dp博弈 #include <bits/stdc++.h> using namespace std; int x,a,b; const int N=1e6+10; int dp[N]; //1代表先手赢,-1代表先手输 int fun(int x){ if(dp[x]!=0){ return dp[ 阅读全文
posted @ 2026-03-12 22:04 peter_shen 阅读(9) 评论(0) 推荐(0)
摘要: 第一遍想到这个方法就直接写了。 第二次做到这个题目,压根就没敢写这个时间复杂度的方法 #include <bits/stdc++.h> using namespace std; const int N=305; int n; long long w[N]; long long dp[N][N]; l 阅读全文
posted @ 2026-03-12 16:24 peter_shen 阅读(12) 评论(0) 推荐(0)
摘要: 记忆DP 注意对于judge()函数我可以去掉,使用另一个dp来对所有可能l,r判断是否为回文串 #include<bits/stdc++.h> using namespace std; int n,q; const int N=1010; int dp[N][N]; char s[N]; bool 阅读全文
posted @ 2026-03-12 15:18 peter_shen 阅读(11) 评论(0) 推荐(0)
摘要: #include <bits/stdc++.h> using namespace std; int n; const int N=100000+10; int dp[N]; int tag[N]; int w[N]; int main(){ while(scanf("%d",&n)!=EOF){ f 阅读全文
posted @ 2026-03-12 12:41 peter_shen 阅读(9) 评论(0) 推荐(0)
摘要: 二维dp #include<bits/stdc++.h> using namespace std; const int N=1010; char s1[N]; char s2[N]; int dp[N][N]; int main(){ while(scanf("%s%s",s1+1,s2+1)!=E 阅读全文
posted @ 2026-03-12 12:20 peter_shen 阅读(11) 评论(0) 推荐(0)
上一页 1 2 3 4 5 6 7 ··· 10 下一页