正文
增加 4 行删除 0 行
28 行未改动293031323334353635 行未改动727374757677787980818283848526 行未改动1121131141151161171181198 行未改动28 行未改动- 末尾状态可以启发 DP 状态的设计。例题:[P10041](https://www.luogu.com.cn/problem/P10041)。- 树形 DP 状态与根链相关时可以考虑重链剖分。例题:[P5391](https://www.luogu.com.cn/problem/P5391),[HDU6566](https://acm.hdu.edu.cn/showproblem.php?pid=6566)。- 看起来很难优化的 DP 可以考虑 CDQ 分治。例题:[QOJ7899](https://qoj.ac/problem/7899)。- 贡献提前/延后计算,在当前 DP 状态下无法良好维护的东西延后到后面的状态中计算。例题:[P2365](https://www.luogu.com.cn/problem/P2365),[P14364](https://www.luogu.com.cn/problem/P14364),[CF1608F](https://codeforces.com/problemset/problem/1608/F)。## 数学- Raney 引理可以用于求解一类前缀和非负的计数问题。例题:[P6672](https://www.luogu.com.cn/problem/P6672),[P12969](https://www.luogu.com.cn/problem/P12969)。35 行未改动## 图论- 图论问题经常考虑 DFS 生成树转化成树上问题。例题:[P11976](https://www.luogu.com.cn/problem/P11976),[CF1361E](https://codeforces.com/problemset/problem/1361/E)。- Bellman-Ford/Dijkstra 求最短路可以推广成图上 DP 的形式,同样要满足松弛的贪心性质。两者的区别在于 Dijkstra-style 的 DP 通常满足某种单调性。例题:[P13534](https://www.luogu.com.cn/problem/P13534),[AGC072E](https://atcoder.jp/contests/agc072/tasks/agc072_e),[CF827F](https://www.luogu.com.cn/problem/CF827F)。- 偏序关系考虑图论建模。例题:[ARC165D](https://atcoder.jp/contests/arc165/tasks/arc165_d)。- 形如权值差不超过 $1$ 的限制考虑图论建模后变成欧拉回路/路径相关。例题:[P9731](https://www.luogu.com.cn/problem/P9731),[CF1610F](https://codeforces.com/problemset/problem/1610/F),[P7816](https://www.luogu.com.cn/problem/P7816)。- Hall 定理存在多种推广:- 左右部点数相同的 $k$ 正则二分图(所有点的度数都是 $k$)一定存在完美匹配。- 二分图有 $m$ 组完美匹配的充要条件是 $m|S|\leq |N(S)|$。例题:[ABC317G](https://atcoder.jp/contests/abc317/tasks/abc317_g)。- 二分图的最大匹配为 $|V_L|-\max_{S\subseteq V_L}\left\{|S|-|N(S)|\right\}$,常与数据结构配合使用。例题:[P12559](https://www.luogu.com.cn/problem/P12559),[ARC076D](https://atcoder.jp/contests/arc076/tasks/arc076_d)。- 平面图满足欧拉定理,即 $|V|-|E|+|F|=C$。例题:[P3776](https://www.luogu.com.cn/problem/P3776)。- 拓扑排序时,当前出队的点和队列中剩余的点不可达。例题:[CF1062F](https://codeforces.com/problemset/problem/1062/F)。- 最小化路径上最大边权的问题考虑建出最小生成树求解。例题:[P1967](https://www.luogu.com.cn/problem/P1967),[P2245](https://www.luogu.com.cn/problem/P2245),[P13548](https://www.luogu.com.cn/problem/P13548)。- 二分图边染色可以 $\mathcal{O}(nm)$ 地把二分图划分成多个完美匹配。例题:[P10062](https://www.luogu.com.cn/problem/P10062)。26 行未改动- 平方串(也就是形如 $XX$ 的串)相关问题,考虑枚举 $|X|=len$,在字符串中每隔 $len$ 个位置放一个断点,这样每个长度为 $2len$ 的平方串都会经过恰好 $2$ 个断点,把问题转化为相邻段的 LCP 相关。例题:[P1117](https://www.luogu.com.cn/problem/P1117),[CF319D](https://codeforces.com/problemset/problem/319/D)。- 字符串子串比较可以用 Hash 二分求出 LCP,在 LCP 后一位比较,从而做到 $\mathcal{O}(\log{n})$ 比较,常数较小。- 一个字符串的所有排名在 $[L,R]$ 中的后缀的本质不同前缀个数为 $\sum\limits_{i=L}^r(n-sa_i+1)-\sum\limits_{i=L+1}^Rht_i$。例题:[P4143](https://www.luogu.com.cn/problem/P4143),[P3181](https://www.luogu.com.cn/problem/P3181),[P4248](https://www.luogu.com.cn/problem/P4248)。## 计算几何- 一次函数 $\min/\max$ 考虑维护凸壳。例题:[P12569](https://www.luogu.com.cn/problem/P12569)。8 行未改动28 行未改动29303132333435363735 行未改动7374757677787980818283848586878826 行未改动1151161171181191201211221238 行未改动28 行未改动- 末尾状态可以启发 DP 状态的设计。例题:[P10041](https://www.luogu.com.cn/problem/P10041)。- 树形 DP 状态与根链相关时可以考虑重链剖分。例题:[P5391](https://www.luogu.com.cn/problem/P5391),[HDU6566](https://acm.hdu.edu.cn/showproblem.php?pid=6566)。- 看起来很难优化的 DP 可以考虑 CDQ 分治。例题:[QOJ7899](https://qoj.ac/problem/7899)。- 贡献提前/延后计算,在当前 DP 状态下无法良好维护的东西延后到后面的状态中计算。例题:[P2365](https://www.luogu.com.cn/problem/P2365),[P14364](https://www.luogu.com.cn/problem/P14364),[CF1608F](https://codeforces.com/problemset/problem/1608/F)。- 可描述为线性变换的 DP,如果需要跑多次,其中转移过程完全相同,只有初值的差别,则可以考虑转置原理,将 DP 倒过来做。例题:[UOJ823](https://uoj.ac/problem/823)、[CF1810G](https://codeforces.com/problemset/problem/1810/G)。## 数学- Raney 引理可以用于求解一类前缀和非负的计数问题。例题:[P6672](https://www.luogu.com.cn/problem/P6672),[P12969](https://www.luogu.com.cn/problem/P12969)。35 行未改动## 图论- 图论问题经常考虑 DFS 生成树转化成树上问题。例题:[P11976](https://www.luogu.com.cn/problem/P11976),[CF1361E](https://codeforces.com/problemset/problem/1361/E)。- Bellman-Ford/Dijkstra 求最短路可以推广成图上 DP 的形式,同样要满足松弛的贪心性质。两者的区别在于 Dijkstra-style 的 DP 通常满足某种单调性。例题:[P13534](https://www.luogu.com.cn/problem/P13534),[AGC072E](https://atcoder.jp/contests/agc072/tasks/agc072_e),[CF827F](https://www.luogu.com.cn/problem/CF827F)。- $n$ 个点的有标号图的连通性是 $\operatorname{Bell}(n)$ 级别的,可以使用最小表示法来表示。例题:[P2109](https://www.luogu.com.cn/problem/P2109)。- 偏序关系考虑图论建模。例题:[ARC165D](https://atcoder.jp/contests/arc165/tasks/arc165_d)。- 形如权值差不超过 $1$ 的限制考虑图论建模后变成欧拉回路/路径相关。例题:[P9731](https://www.luogu.com.cn/problem/P9731),[CF1610F](https://codeforces.com/problemset/problem/1610/F),[P7816](https://www.luogu.com.cn/problem/P7816)。- Hall 定理存在多种推广:- 左右部点数相同的 $k$ 正则二分图(所有点的度数都是 $k$)一定存在完美匹配。- 二分图有 $m$ 组完美匹配的充要条件是 $m|S|\leq |N(S)|$。例题:[ABC317G](https://atcoder.jp/contests/abc317/tasks/abc317_g)。- 二分图的最大匹配为 $|V_L|-\max_{S\subseteq V_L}\left\{|S|-|N(S)|\right\}$,常与数据结构配合使用。例题:[P12559](https://www.luogu.com.cn/problem/P12559),[ARC076D](https://atcoder.jp/contests/arc076/tasks/arc076_d)。- 对于带出入流量的二分图,这张图满流当且仅当对于任意一个左部点集合 $S$,$\sum\limits_{x\in S}in_x\leq \sum\limits_{x\in N(S)}\min(out_x, |S|)$。例题:[P9339](https://www.luogu.com.cn/problem/P9339),[CF1740F](https://codeforces.com/problemset/problem/1740/F)。- 平面图满足欧拉定理,即 $|V|-|E|+|F|=C$。例题:[P3776](https://www.luogu.com.cn/problem/P3776)。- 拓扑排序时,当前出队的点和队列中剩余的点不可达。例题:[CF1062F](https://codeforces.com/problemset/problem/1062/F)。- 最小化路径上最大边权的问题考虑建出最小生成树求解。例题:[P1967](https://www.luogu.com.cn/problem/P1967),[P2245](https://www.luogu.com.cn/problem/P2245),[P13548](https://www.luogu.com.cn/problem/P13548)。- 二分图边染色可以 $\mathcal{O}(nm)$ 地把二分图划分成多个完美匹配。例题:[P10062](https://www.luogu.com.cn/problem/P10062)。26 行未改动- 平方串(也就是形如 $XX$ 的串)相关问题,考虑枚举 $|X|=len$,在字符串中每隔 $len$ 个位置放一个断点,这样每个长度为 $2len$ 的平方串都会经过恰好 $2$ 个断点,把问题转化为相邻段的 LCP 相关。例题:[P1117](https://www.luogu.com.cn/problem/P1117),[CF319D](https://codeforces.com/problemset/problem/319/D)。- 字符串子串比较可以用 Hash 二分求出 LCP,在 LCP 后一位比较,从而做到 $\mathcal{O}(\log{n})$ 比较,常数较小。- 一个字符串的所有排名在 $[L,R]$ 中的后缀的本质不同前缀个数为 $\sum\limits_{i=L}^r(n-sa_i+1)-\sum\limits_{i=L+1}^Rht_i$。例题:[P4143](https://www.luogu.com.cn/problem/P4143),[P3181](https://www.luogu.com.cn/problem/P3181),[P4248](https://www.luogu.com.cn/problem/P4248)。- 将字符串 $s$ 排成 $s'=s_1s_ns_2s_{n-1}\cdots s_ns_1$ 可以将 $s$ 的 border 转化成 $s'$ 的左端点在开头处的偶回文串。例题:[P14380](https://www.luogu.com.cn/problem/P14830),[P3546](https://www.luogu.com.cn/problem/P3546)。## 计算几何- 一次函数 $\min/\max$ 考虑维护凸壳。例题:[P12569](https://www.luogu.com.cn/problem/P12569)。8 行未改动