10 2022 档案
摘要:类似于二分法? 每一部分求到最小值然后合并 #include<bits/stdc++.h> using namespace std; const int N = 310; int n; int s[N]; int f[N][N]; int main() { cin >> n; for (int i
阅读全文
摘要:这个方法是nlogn的而动态规划是n方的 #include<bits/stdc++.h> using namespace std; vector<int> nums; void help(vector<int>& arr, int n){ //找到一个位置的数前面比n小自己比n大或者相等。 int
阅读全文
摘要:输入是 4 5 1 2 3 2 4 1 3 4 3 4 5 2 实际上把他边成 4 5 1 2 1 2 4 1 2 4 1 3 4 1 6 8 1 4 5 1 4 5 1 全部是一就变成01背包问题了 #include<bits/stdc++.h> using namespace std; cons
阅读全文
摘要:#include<bits/stdc++.h> using namespace std; const int N = 1010; int n, m; int v[N], w[N]; int f[N]; int main() { cin >> n >> m; for (int i = 1; i <=
阅读全文
摘要:匈牙利算法 二分图分为a边b边 a边每一个都遍历,然后某一个匹配到了b其中一个,如果a边中其他的也匹配到了这一个,那就让前面那个点先尝试能不能换一个如果可以就成功匹配 如果不行就寻找下一个点 #include<bits/stdc++.h> using namespace std; const int
阅读全文
摘要:用深度优先法,遍历每一个节点然后从他开始子节点,子节点和自己的颜色不一样就可以。 二分图又称作二部图,是图论中的一种特殊模型。 设G=(V,E)是一个无向图,如果顶点V可分割为两个互不相交的子集(A,B),并且图中的每条边(i,j)所关联的两个顶点i和j分别属于这两个不同的顶点集(i in A,j
阅读全文
摘要:把所有边按照权重值从小到大排序,然后一一收入集合,利用联通集判断一条边的两个点是否在一个联通集中 如果在就不收录这条边 #include<bits/stdc++.h> using namespace std; const int N = 100010, M = 200010; int n, m; i
阅读全文
摘要:最小生成树就是把很多个点以及很多条有权边,生成最少且最小的边把所有点连在一起。 #include<bits/stdc++.h> using namespace std; const int N = 510, INF = 0x3f3f3f3f; int n, m; int g[N][N]; //储存边
阅读全文
摘要:#include<bits/stdc++.h> using namespace std; const int N = 510, M = 10010; int n, m, k; int dist[N], backup[N]; struct Edge { int a, b, w; }edges[M];
阅读全文
摘要:时间复杂度为n^2,这个算法之所以不能计算有负权路的原因是他不会走走过的点,比如 (a, b, -1) (a, c, 1) (c, b, -6) Dijkstra算法可以很好地解决无负权图的最短路径问题,但如果出现了负权边,Dijkstra算法就会失效,例如图10-39中设置A为源点时,首先会将点B
阅读全文
摘要:用深度优先解决n皇后问题(一条路走到黑不行再换路) #include<bits/stdc++.h> using namespace std; const int N = 20; char g[N][N]; //这个储存棋盘 bool col[N], dg[N], udg[N]; //记录同列 同对角
阅读全文