摘要: 关于树状数组 cite 以 O(logn) 的时间复杂度查找、改变前缀和数组 要注意: 树状数组 c 里面存的不是对应点的值、也不是前缀和的值,是树状数组的值 但是可以利用树状数组对一个区间进行 log n 的时间复杂度的改变或求某点前缀和 //O(nlogn) 初始化 for(int i = 1; 阅读全文
posted @ 2021-10-11 20:10 Xuuxxi 阅读(27) 评论(0) 推荐(0) 编辑
摘要: 蒙德里安的梦想 #include<iostream> #include<cstring> #include<algorithm> #include<vector> using namespace std; typedef long long ll; const int N = 12; const i 阅读全文
posted @ 2021-10-05 19:07 Xuuxxi 阅读(35) 评论(0) 推荐(0) 编辑
摘要: 一般ACM或者笔试题的时间限制是1秒或2秒。 在这种情况下,C++代码中的操作次数控制在 107∼108107∼108 为最佳。 下面给出在不同数据范围下,代码的时间复杂度和算法该如何选择: 1. n≤30, 指数级别, dfs+剪枝,状态压缩dp 2. n≤100 => O(n3),floyd,d 阅读全文
posted @ 2021-09-01 12:15 Xuuxxi 阅读(26) 评论(0) 推荐(0) 编辑
摘要: 背包问题 01背包 每件物品最多只用一次 01背包 将状态f[i][j]优化到一维f[j],实际上只需要做一个等价变形。 为什么可以这样变形呢?我们定义的状态f[i][j]可以求得任意合法的i与j最优解,但题目只需要求得最终状态f[n][m],因此我们只需要一维的空间来更新状态。 (1)状态f[j] 阅读全文
posted @ 2021-08-15 18:52 Xuuxxi 阅读(40) 评论(0) 推荐(0) 编辑
摘要: 原理 对二分图的一边进行匹配尝试,最后再次遍历统计成功次数 O(nm) //但是实际情况一般少于O(nm) 模板 二分图的最大匹配 #include<iostream> #include<cstring> using namespace std; const int N = 100010; int 阅读全文
posted @ 2021-07-31 02:41 Xuuxxi 阅读(154) 评论(0) 推荐(0) 编辑
摘要: 原理 1,2为两种颜色,0为未染色 根据染色是否成功判断是否为二分图 模板 染色法判定二分图 #include<iostream> #include<cstring> #include<algorithm> using namespace std; const int N = 200010; int 阅读全文
posted @ 2021-07-30 14:51 Xuuxxi 阅读(201) 评论(0) 推荐(0) 编辑
摘要: 使用 稀疏图求最小生成树边权和 O(mlogm) 模板 Kruskal算法求最小生成树 #include<iostream> #include<algorithm> using namespace std; const int N = 200010; int n,m; int p[N]; //并查集 阅读全文
posted @ 2021-07-27 16:29 Xuuxxi 阅读(32) 评论(0) 推荐(0) 编辑
摘要: 用处 求最小生成树的权和时使用 稠密图 O(nm) 模板 Prim算法求最小生成树 #include<iostream> #include<algorithm> #include<cstring> using namespace std; const int N = 510,INF = 0x3f3f 阅读全文
posted @ 2021-07-27 15:30 Xuuxxi 阅读(34) 评论(0) 推荐(0) 编辑
摘要: 多源路算法(O(n ^ 3)) Floyd求最短路 #include<iostream> #include<algorithm> using namespace std; const int N = 210,null = 0x3f3f3f3f; int d[N][N]; int n,m; //遍历更 阅读全文
posted @ 2021-07-26 15:10 Xuuxxi 阅读(37) 评论(0) 推荐(0) 编辑
摘要: spfa(O(m) ~ O(nm)) 可以在正权边的时候代替dijkstra算法,如果时间复杂度为O(nm)就不行了 没有负权回路的时候可以代替bellman-ford算法,一般都用spfa spfa是对bellman-ford的bfs优化版本 spfa求最短路 #include<iostream> 阅读全文
posted @ 2021-07-25 11:49 Xuuxxi 阅读(12) 评论(0) 推荐(1) 编辑