摘要: 洛谷P3386二分图最大匹配 || 匈牙利算法 给定一张二分图,其左部点集大小为 n,右部点集大小为 m,共k条边,请求出其最大匹配。 需要注意的是,在一轮递归中,每个右部点只能被访问一次。 #include <bits/stdc++.h> using namespace std; const in 阅读全文
posted @ 2020-12-06 13:19 .Ivorelectra 阅读(145) 评论(0) 推荐(0) 编辑
摘要: 最长上升子串(非dp版本) int j = 2; int ans = 1, cnt = 1; while(j <= n)//每次进while,第j个位置都准备开始判断 { if(x[j] >= x[j-1]) { ++cnt; } else { ans = max(ans, cnt); cnt = 阅读全文
posted @ 2020-12-01 23:43 .Ivorelectra 阅读(191) 评论(0) 推荐(0) 编辑
摘要: B. So Easy || 思维 行列之差,注意边界处理 #include <bits/stdc++.h> using namespace std; int a[1111][1111]; int main() { int n; cin >> n; int idx, idy; for(int i = 阅读全文
posted @ 2020-11-30 09:47 .Ivorelectra 阅读(80) 评论(0) 推荐(0) 编辑
摘要: 完全二叉树 由后序遍历求层序遍历 int p[300], num[300], cur, n; void dfs(int x) { if(x > n) return; dfs(2 * x); dfs(2 *x + 1); p[++cur] = x; //p[i] 表示后序第i个结点是层次遍历的第p[i 阅读全文
posted @ 2020-11-28 20:50 .Ivorelectra 阅读(191) 评论(0) 推荐(0) 编辑
摘要: 异或XOR的性质: 1. 交换律 2. 结合律 3. x^x = 0 -> 偶数个异或为0 4. x^0 = x -> 奇数个异或为本身 5. 自反性:a^b^b = a^0 =a 阅读全文
posted @ 2020-11-14 12:36 .Ivorelectra 阅读(183) 评论(0) 推荐(0) 编辑
摘要: 最长对称子串 || 区间dp || 马拉车 dp[i][j]表示区间[i, j]是否为回文串,若是则为1,不是则为0。 边界条件: 1. 区间长度为1,dp为1。(奇数个字符递推的起始情况) 2. 区间长度为2,且两个字符相同,则dp为1。(偶数个字符递推的起始情况) 3. 右边界不超过n。 转移: 阅读全文
posted @ 2020-11-12 02:50 .Ivorelectra 阅读(133) 评论(0) 推荐(0) 编辑
摘要: 快速幂 ll qpow(ll a, ll b) { ll t = 1; for(; b; b >>= 1, a = a * a % mod) if(b & 1) t = t * a % mod; return t; } 求逆元: 若a * a-1 ≡ 1 (mod p),我们就称 a-1 为 a 在 阅读全文
posted @ 2020-11-06 00:19 .Ivorelectra 阅读(58) 评论(0) 推荐(0) 编辑
摘要: C. Chef Monocarp || dp 1. 首先得到结论:先做好的菜应该先出(至少不慢:eg. 做好5 6 出菜1 2) 那么先把菜按做好的时间排序。 2. 定义dp[i][j]为:前i分钟做了j道菜,时间差的最小值。那这个状态是由什么转移过来的呢?考虑第i分钟是否做了第j道菜。如果做了,那 阅读全文
posted @ 2020-11-01 02:13 .Ivorelectra 阅读(77) 评论(0) 推荐(0) 编辑
摘要: C. Perform Easily || 尺取法(滑动窗口) 注意六倍问题 #include <cstdio> #include <algorithm> using namespace std; const int maxn = 1e5 +9; const int INF = 1e9 + 7; in 阅读全文
posted @ 2020-10-27 02:00 .Ivorelectra 阅读(126) 评论(0) 推荐(0) 编辑
摘要: POJ 3061 Subsequence || 尺取法 给定一个序列,求最短的连续子序列长度,满足其各项和大于等于S。没有则输出0。序列都为正数。 (I) O(nlogn) 做法:dp (II) O(n) 做法:尺取法 如果一个区间其和大于等于S了,那么不需要在向后推进右端点了,因为其和也肯定大于等 阅读全文
posted @ 2020-10-23 09:32 .Ivorelectra 阅读(99) 评论(0) 推荐(0) 编辑