};
```
-~~看上去是不是很简单呢(这题高精度卡常……)~~
如果看懂了就可以尝试下一道类似的题: [Luogu P2123 皇后游戏](https://www.luogu.org/problemnew/show/P2123)
## 后悔法
**求解** :对整个问题设最优值,枚举合并点,将问题分解为左右两个部分,最后合并两个部分的最优值得到原问题的最优值。
-??? note " 例题[「NOI1995」石子合并](https://www.luogu.org/problemnew/show/P1880)"
+??? note " 例题[「NOI1995」石子合并](https://loj.ac/problem/10147)"
题目大意:在一个环上有 $n$ 个数 $a_1,a_2,...,a_n$ ,进行 $n-1$ 次合并操作,每次操作将相邻的两堆合并成一堆,能获得新的一堆中的石子数量的和的得分。你需要最大化你的得分。
考虑不在环上,而在一条链上的情况。
## 几道练习题
- [NOI2001 炮兵阵地](https://www.luogu.org/problemnew/show/P2704)
+ [NOI2001 炮兵阵地](https://loj.ac/problem/10173)
[「USACO06NOV」玉米田 Corn Fields](https://www.luogu.org/problemnew/show/P1879)
[AHOI2009 中国象棋](https://www.luogu.org/problem/P2051)
- [九省联考 2018 一双木棋](https://www.luogu.org/problemnew/show/P4363)
+ [九省联考 2018 一双木棋](https://loj.ac/problem/2471)
}
```
-???+note " 例题[「CQOI2016」K 远点对](https://www.luogu.org/problem/P4357)"
+???+note " 例题[「CQOI2016」K 远点对](https://loj.ac/problem/2043)"
给定平面上的 $n$ 个点 $(x_i,y_i)$ ,求欧几里得距离下的第 $k$ 远无序点对之间的距离。
$n\le 100000 , 1\le k\le 100 , 0\le x_i,y_i<2^{31}$
- [luogu P3690【模板】Link Cut Tree(动态树)](https://www.luogu.org/problemnew/show/P3690)
- [「SDOI2011」染色](https://www.luogu.org/problemnew/show/P2486)
-- [「SHOI2014」三叉神经树](https://www.luogu.org/problemnew/show/P4332)
+- [「SHOI2014」三叉神经树](https://loj.ac/problem/2187)
## 维护连通性质
### 习题
- [「WC2006」水管局长](https://www.luogu.org/problem/P4172)
-- [「BJWC2010」](https://www.luogu.org/problemnew/show/P4180)
+- [「BJWC2010」严格次小生成树](https://www.luogu.org/problemnew/show/P4180)
- [「NOI2014」魔法森林](http://uoj.ac/problem/3)
## 维护子树信息
LCT 不擅长维护子树信息。统计一个结点所有虚子树的信息,就可以求得整棵树的信息。
-???+note " 例题[「BJOI2014」大融合](https://www.luogu.org/problem/P4219)"
+???+note " 例题[「BJOI2014」大融合](https://loj.ac/problem/2230)"
给定 $n$ 个结点和 $q$ 次操作,每个操作为如下形式:
1. `A x y` 在结点 $x$ 和 $y$ 之间连接一条边。
## 习题
- [「SCOI2010」序列操作](https://www.luogu.org/problem/P2572)
-- [「SHOI2015」脑洞治疗仪](https://www.luogu.org/problem/P4344)
+- [「SHOI2015」脑洞治疗仪](https://loj.ac/problem/2037)
- [「Luogu 2787」理理思维](https://www.luogu.org/problemnew/show/P2787)
- [「Luogu 4979」矿洞:坍塌](https://www.luogu.org/problemnew/show/P4979)
[严格次小生成树](https://www.luogu.org/problemnew/show/P4180)
- [货车运输](https://www.luogu.org/problemnew/show/P1967)
+ [货车运输](https://loj.ac/problem/2610)
[跑路](https://www.luogu.org/problemnew/show/P1613)
## 习题
- [严格次小生成树](https://www.luogu.org/problemnew/show/P4180)
-- [货车运输](https://www.luogu.org/problemnew/show/P1967)
+- [货车运输](https://loj.ac/problem/2610)
- [跑路](https://www.luogu.org/problemnew/show/P1613)
## 习题
-- [NOIP 2012 国王游戏](https://www.luogu.org/problemnew/show/P1080)
+- [NOIP 2012 国王游戏](https://loj.ac/problem/2603)
- [SPOJ - Fast Multiplication](http://www.spoj.com/problems/MUL/en/)
- [SPOJ - GCD2](http://www.spoj.com/problems/GCD2/)
- [UVA - Division](https://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=1024)
- [SPOJ MOD](https://www.spoj.com/problems/MOD/) 模板
- [SDOI2013 随机数生成器](https://www.luogu.org/problem/P3306)
- [BZOJ1319 Discrete Roots](http://www.lydsy.com/JudgeOnline/problem.php?id=1319) 模板
-- [SDOI2011 计算器](https://www.luogu.org/problemnew/show/P2485) 模板
+- [SDOI2011 计算器](https://loj.ac/problem/10214) 模板
- [Luogu4195【模板】exBSGS/Spoj3105 Mod](https://www.luogu.org/problemnew/show/P4195) 目标
- [Codeforces - Lunar New Year and a Recursive Sequence](https://codeforces.com/contest/1106/problem/F)
[乘法逆元 2](https://loj.ac/problem/152)
- [同余方程](https://www.luogu.org/problemnew/show/P1082)
+ [「NOIP2012」同余方程](https://loj.ac/problem/2605)
[「AHOI2005」洗牌](https://www.luogu.org/problem/P2054)
- [「SDOI2016」排列计数](https://www.luogu.org/problemnew/show/P4071)
+ [「SDOI2016」排列计数](https://loj.ac/problem/2034)
形如 $ax \equiv b \pmod c$ 的方程被称为 **线性同余方程** (Congruence Equation)。
- [「NOIP2012」同余方程](https://www.luogu.org/problemnew/show/P1082)
+ [「NOIP2012」同余方程](https://loj.ac/problem/2605)
## 求解方法
## 习题
- [Luogu3807【模板】卢卡斯定理](https://www.luogu.org/problemnew/show/P3807)
-- [SDOI2010 古代猪文 卢卡斯定理](https://www.luogu.org/problemnew/show/P2480)
+- [SDOI2010 古代猪文 卢卡斯定理](https://loj.ac/problem/10229)
- [Luogu4720【模板】扩展卢卡斯](https://www.luogu.org/problemnew/show/P4720)
}
```
-### [「SDOI2015」约数个数和](https://www.luogu.org/problemnew/show/P3327)
+### [「SDOI2015」约数个数和](https://loj.ac/problem/2185)
多组数据,求
}
```
-??? note "例题"
- 做一做 [Luogu P1226](https://www.luogu.org/problemnew/show/P1226)
+模板:[Luogu P1226](https://www.luogu.org/problemnew/show/P1226)
## 应用
## 习题
-- [JSOI2016 最佳团体](https://www.luogu.org/problem/P4322)
-- [SDOI2017 新生舞会](https://www.luogu.org/problem/P3705)
+- [JSOI2016 最佳团体](https://loj.ac/problem/2071)
+- [SDOI2017 新生舞会](https://loj.ac/problem/2003)
- [UVa1389 Hard Life](https://www.luogu.org/problem/UVA1389)
所谓 **meet-in-middle** , 就是让 DFS 的状态在中间的时候碰面。我们知道,如果一个暴力 dfs 有 $K$ 个转移,那么它的时间复杂度(大多数情况)是 $O(K^N)$ 的。那我们就想,当 $N$ 到达一定程度时,TLE 会变成必然。
-例题 [Luogu P2962](https://www.luogu.org/problemnew/show/P2962)
+例题 [「USACO09NOV」灯Lights](https://www.luogu.org/problemnew/show/P2962)
我们正常想,如果这道题暴力 DFS 找开关灯的状态,时间复杂度就是 $O(2^{n})$ , 显然超时。不过,如果我们用 **meet-in-middle** 的话,时间复杂度将会变为 $O(2^{n/2} \times 2)$ 而已。 **meet-in-middle** 就是让我们先找一半的状态,也就是 $1$ 到 $\mathrm{mid}$ 的状态,再找剩下的状态就可以了。我们把前半段的状态全部存储在 `map` 里面,然后在找后半段的状态的时候,先判断后半段是不是都合法,就可以判断上半段有没有配对的上半段使得整段合法。
## 例题
-???+note "[「HEOI2015」最短不公共子串](https://www.luogu.org/problem/P4112)"
+???+note "[「HEOI2015」最短不公共子串](https://loj.ac/problem/2123)"
给你两个由小写英文字母组成的串 $A$ 和 $B$,求: