随笔分类 -  网络流

摘要:洛谷传送门 CF 传送门 题目看着感觉很像最大流,不妨建模,\(S \to i\),容量为 \(a_i\);\(i \to T\),容量为 \(b_i\);\(i \to i + 1\),容量为 \(c_i\)。答案是这个图的最大流。 考虑最大流转最小割。观察到 \(S \to i\) 和 \(i 阅读全文
posted @ 2024-01-09 21:17 zltzlt 阅读(29) 评论(0) 推荐(0)
摘要:洛谷传送门 CF 传送门 考虑费用流,对于每一行建两个点 \(i_0, i_1\),分别代表这一行的所有 \(0, 1\)。同样每一列建两个点 \(j_0, j_1\)。源点分别向 \(i_0, i_1\) 连流量为这一行要求的 \(0\) 或 \(1\) 的个数,费用为 \(0\)。同理连汇点。 阅读全文
posted @ 2023-12-21 15:14 zltzlt 阅读(72) 评论(0) 推荐(0)
摘要:洛谷传送门 CF 传送门 要求最大化收益加上支出,又因为每个字符有染红和染蓝两种选择,考虑最小割模型。可以看成是一开始先获得 \(r_i + b_i\) 的收益,然后对于每个 \(0\),连边 \((S, i, b_i), (i, T, r_i)\);对于每个 \(1\),连边 \((S, i, r 阅读全文
posted @ 2023-11-16 19:05 zltzlt 阅读(41) 评论(0) 推荐(0)
摘要:[洛谷传送门](https://www.luogu.com.cn/problem/AT_abc317_g "洛谷传送门") [AtCoder 传送门](https://atcoder.jp/contests/abc317/tasks/abc317_g "AtCoder 传送门") 考虑转化成匹配问题 阅读全文
posted @ 2023-08-27 21:40 zltzlt 阅读(116) 评论(0) 推荐(0)
摘要:[洛谷传送门](https://www.luogu.com.cn/problem/CF1525F "洛谷传送门") [CF 传送门](https://codeforces.com/problemset/problem/1525/F "CF 传送门") 套路地,将 DAG 的最小不交路径覆盖转化为点数 阅读全文
posted @ 2023-07-11 17:01 zltzlt 阅读(40) 评论(0) 推荐(0)
摘要:[洛谷传送门](https://www.luogu.com.cn/problem/AT_abc227_h "洛谷传送门") [AtCoder 传送门](https://atcoder.jp/contests/abc227/tasks/abc227_h "AtCoder 传送门") 好奇特的题。 考虑 阅读全文
posted @ 2023-06-28 18:20 zltzlt 阅读(35) 评论(0) 推荐(0)
摘要:[洛谷传送门](https://www.luogu.com.cn/problem/AT_abc225_g "洛谷传送门") [AtCoder 传送门](https://atcoder.jp/contests/abc225/tasks/abc225_g "AtCoder 传送门") 感觉是一种很新的建 阅读全文
posted @ 2023-06-05 22:15 zltzlt 阅读(26) 评论(0) 推荐(0)
摘要:[洛谷传送门](https://www.luogu.com.cn/problem/AT_abc259_g "洛谷传送门") [AtCoder 传送门](https://atcoder.jp/contests/abc259/tasks/abc259_g "AtCoder 传送门") 记 $b_i = 阅读全文
posted @ 2023-06-04 22:03 zltzlt 阅读(22) 评论(0) 推荐(0)
摘要:[洛谷传送门](https://www.luogu.com.cn/problem/AT_abc214_h "洛谷传送门") [AtCoder 传送门](https://atcoder.jp/contests/abc214/tasks/abc214_h "AtCoder 传送门") 好毒瘤啊…… 首先 阅读全文
posted @ 2023-06-03 08:31 zltzlt 阅读(47) 评论(0) 推荐(0)
摘要:[洛谷传送门](https://www.luogu.com.cn/problem/AT_abc193_f "洛谷传送门") [AtCoder 传送门](https://atcoder.jp/contests/abc193/tasks/abc193_f "AtCoder 传送门") 复习一下最小割。 阅读全文
posted @ 2023-05-25 13:27 zltzlt 阅读(35) 评论(0) 推荐(0)
摘要:洛谷传送门 AtCoder 传送门 很棒的 flow 题,考虑建二分图。 源点向每种零食连边权为 $a_i$ 的边,每种零食向每个孩子连边权为 $b_j$ 的边,每个孩子向汇点连边权为 $c_j$ 的边,这个图的最大流就是答案。 直接跑最大流肯定 T,考虑最大流等价于求这个图的最小割,因此转而求最小 阅读全文
posted @ 2023-04-26 13:39 zltzlt 阅读(21) 评论(0) 推荐(0)
摘要:洛谷传送门 CF 传送门 考虑只有一个排列怎么做。有一个结论是答案为 $n\ -$ 置换环个数,即每个环都会选择一个点不操作,其他点都操作。 接下来考虑两个排列,显然当 $x$ 在 $a$ 和 $b$ 中都不操作,$x$ 才能不操作。设 $x$ 在 $a$ 中所在环为 $pa_x$,在 $b$ 中所 阅读全文
posted @ 2023-01-19 17:39 zltzlt 阅读(43) 评论(0) 推荐(0)
摘要:问题 有 \(n\) 个整数变量 \(x_i\)。\(x_i\) 可以取 \([1,m]\),取 \(j\) 需要 \(a_{i,j}\) 的代价。有若干个约束,形如 \(x_{u_i} \le x_{v_i} + w_i\)。给变量赋值,最小化总代价。 建模 考虑求最小割。对每个整数变量拆 \(m 阅读全文
posted @ 2023-01-17 09:35 zltzlt 阅读(602) 评论(0) 推荐(1)
摘要:洛谷传送门 AtCoder 传送门 下文令 $|S| = n$。 引理: 一个字符串中本质不同的回文串数量 $\le n$。 证明: 考虑每在字符串末尾添加一个字符,本质不同回文串数量最多增加 $1$。 考虑反证,设字符串在添加 $s_n$ 后,$s_{x...n}$ 与 $s_{y...n}$(令 阅读全文
posted @ 2022-11-23 17:21 zltzlt 阅读(49) 评论(0) 推荐(0)
摘要:[AtCoder 传送门](https://atcoder.jp/contests/abc263/tasks/abc263_g "AtCoder 传送门") [洛谷传送门](https://www.luogu.com.cn/problem/AT_abc263_g "洛谷传送门") ## 题意 有 $ 阅读全文
posted @ 2022-10-22 19:43 zltzlt 阅读(54) 评论(0) 推荐(0)