正文
增加 245 行删除 63 行
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213# 搜索## DFS[P1731 [NOI1999] 生日蛋糕](https://www.luogu.com.cn/problem/P1731)[代码](https://www.luogu.com.cn/paste/yk3e2l90)[UVA529 Addition Chains](https://www.luogu.com.cn/problem/UVA529)[代码](https://www.luogu.com.cn/paste/s4fdufx5)[P4799 [CEOI 2015] 世界冰球锦标赛 (Day2)](https://www.luogu.com.cn/problem/P4799)[代码](https://www.luogu.com.cn/paste/9s7focc6)[P1156 垃圾陷阱](https://www.luogu.com.cn/problem/P1156)[代码](https://www.luogu.com.cn/paste/qteyqb1i)[P1004 [NOIP 2000 提高组] 方格取数](https://www.luogu.com.cn/problem/P1004)[代码](https://www.luogu.com.cn/paste/hdiordle)[P1541 [NOIP 2010 提高组] 乌龟棋](https://www.luogu.com.cn/problem/P1541)[代码](https://www.luogu.com.cn/paste/kmdbeb6i)## BFS[P1379 八数码难题](https://www.luogu.com.cn/problem/P1379)[代码](https://www.luogu.com.cn/paste/ga0ehl8z)[P1551 亲戚](https://www.luogu.com.cn/problem/P1551)[代码](https://www.luogu.com.cn/paste/kvld5414)# 前缀和[【一维前缀和模板】——P8218 【深进1.例1】求区间和](https://www.luogu.com.cn/problem/P8218)[代码](https://www.luogu.com.cn/paste/6dfwubjm)[【二维前缀和模板】——P1719 最大加权矩形](https://www.luogu.com.cn/problem/P1719)[代码](https://www.luogu.com.cn/paste/n7t9i7ep)[P1314 [NOIP 2011 提高组] 聪明的质监员](https://www.luogu.com.cn/problem/P1314)[代码](https://www.luogu.com.cn/paste/gjv1tapk)# 差分[【差分模板】——P2367 语文成绩](https://www.luogu.com.cn/problem/P2367)[代码](https://www.luogu.com.cn/paste/58gvff49)[【二维差分】——P3397 地毯](https://www.luogu.com.cn/problem/P3397)[代码](https://www.luogu.com.cn/paste/tf9054e7)# 离散化[【离散化模板】——P1496 火烧赤壁](https://www.luogu.com.cn/problem/P1496)[代码](https://www.luogu.com.cn/paste/pzq0lxk8)[【二维离散化】——P1884 [USACO12FEB] Overplanting S](https://www.luogu.com.cn/problem/P1884)[代码](https://www.luogu.com.cn/paste/i412nsed)[P1904 天际线](https://www.luogu.com.cn/problem/P1904)[代码](https://www.luogu.com.cn/paste/6k5kbhhw)# 稀疏表(ST表)[P3865 【模板】ST 表 && RMQ 问题](https://www.luogu.com.cn/problem/P3865)[代码](https://www.luogu.com.cn/paste/wczgxsuo)[【双ST表】——P2880 [USACO07JAN] Balanced Lineup G](https://www.luogu.com.cn/problem/P2880)[代码](https://www.luogu.com.cn/paste/ev6ejfvn)[P7333 [JRKSJ R1] JFCA](https://www.luogu.com.cn/problem/P7333)[代码](https://www.luogu.com.cn/paste/9lhxbcvh)[P8818 [CSP-S 2022] 策略游戏](https://www.luogu.com.cn/problem/P8818)[代码](https://www.luogu.com.cn/paste/nxanxd4m)# 堆[堆排序代码](https://www.luogu.com.cn/paste/ym92sdyq)[P1801 黑匣子](https://www.luogu.com.cn/problem/P1801)[代码](https://www.luogu.com.cn/paste/wc0szb3h)[P2085 最小函数值](https://www.luogu.com.cn/problem/P2085)[代码](https://www.luogu.com.cn/paste/irsluzft)# 树状数组[P3374 【模板】树状数组 1](https://www.luogu.com.cn/problem/P3374)[代码](https://www.luogu.com.cn/paste/mx4rvxl6)[P3368 【模板】树状数组 2](https://www.luogu.com.cn/problem/P3368)[代码](https://www.luogu.com.cn/paste/ogtraoeo)[P1908 逆序对](https://www.luogu.com.cn/problem/P1908)[代码](https://www.luogu.com.cn/paste/lbe11o30)# 线段树[P3372 【模板】线段树 1](https://www.luogu.com.cn/problem/P3372)[代码](https://www.luogu.com.cn/paste/wez36t8w)[P2357 守墓人](https://www.luogu.com.cn/problem/P2357)[代码](https://www.luogu.com.cn/paste/n8cewdl0)[P1253 扶苏的问题](https://www.luogu.com.cn/problem/P1253)[代码](https://www.luogu.com.cn/paste/lrd1304m)[P3373 【模板】线段树 2](https://www.luogu.com.cn/problem/P3373)[代码](https://www.luogu.com.cn/paste/x7q7esky)[P1438 无聊的数列](https://www.luogu.com.cn/problem/P1438)[代码](https://www.luogu.com.cn/paste/ljsg3q0v)# 分块[P2357 守墓人](https://www.luogu.com.cn/problem/P2357)[代码](https://www.luogu.com.cn/paste/akzjpk22)# 排序[P1080 [NOIP 2012 提高组] 国王游戏](https://www.luogu.com.cn/problem/P1080)[代码](https://www.luogu.com.cn/paste/t5e2hszl)## 归并排序[P1908 逆序对](https://www.luogu.com.cn/problem/P1908)[代码](https://www.luogu.com.cn/paste/7dsm4jk6)# 树[P5908 猫猫和企鹅](https://www.luogu.com.cn/problem/P5908)[代码](https://www.luogu.com.cn/paste/91dfbmqj)[【树的重心模板】—— P1395 会议](https://www.luogu.com.cn/problem/P1395)[代码](https://www.luogu.com.cn/paste/y1vwwoxp)[P3379 【模板】最近公共祖先(LCA)](https://www.luogu.com.cn/problem/P3379)[代码](https://luogu.com.cn/paste/af38j9um)[P2052 [NOI2011] 道路修建](https://www.luogu.com.cn/problem/P2052)[代码](https://www.luogu.com.cn/paste/ejbls0hh)[P1351 [NOIP 2014 提高组] 联合权值](https://www.luogu.com.cn/problem/P1351)[代码](https://www.luogu.com.cn/paste/y415bfh8)[P3128 [USACO15DEC] Max Flow P](https://www.luogu.com.cn/problem/P3128)[代码](https://www.luogu.com.cn/paste/l9das1ms)[P5536 【XR-3】核心城市](https://www.luogu.com.cn/problem/P5536)[代码](https://www.luogu.com.cn/paste/c1lwkf5a)# 动态规划## 背包问题[【01背包】——P1048 [NOIP 2005 普及组] 采药](https://www.luogu.com.cn/problem/P1048)[代码](https://www.luogu.com.cn/paste/3z1xj9pt)[【完全背包】——P1616 疯狂的采药](https://www.luogu.co[代码](https://www.luogu.com.cn/paste/lrcvvpmi)m.cn/problem/P1616)[代码](https://www.luogu.com.cn/paste/lllx48k9)[P1064 [NOIP 2006 提高组] 金明的预算方案](https://www.luogu.com.cn/problem/P1064)[代码](https://www.luogu.com.cn/paste/kc63da4v)[P1156 垃圾陷阱](https://www.luogu.com.cn/problem/P1156)[代码](https://www.luogu.com.cn/paste/2g7m0jd4)## 线性动态规划[P2285 [HNOI2004] 打鼹鼠](https://www.luogu.com.cn/problem/P2285)[代码](https://www.luogu.com.cn/paste/tnk58bs4)[P1020 [NOIP 1999 提高组] 导弹拦截](https://www.luogu.com.cn/problem/P1020)[代码【不优化做法】](https://www.luogu.com.cn/paste/xb1faasa)[P1725 琪露诺](https://www.luogu.com.cn/problem/P1725)[代码](https://www.luogu.com.cn/paste/lrcvvpmi)[P1439 【模板】最长公共子序列](https://www.luogu.com.cn/problem/P1439)[代码](https://www.luogu.com.cn/paste/nha8zqum)[P1435 [IOI 2000] 回文字串](https://www.luogu.com.cn/problem/P1435)[代码](https://www.luogu.com.cn/paste/k4j5nzx2)[P1004 [NOIP 2000 提高组] 方格取数](https://www.luogu.com.cn/problem/P1004)[代码](https://www.luogu.com.cn/paste/8ntaju99)[P1541 [NOIP 2010 提高组] 乌龟棋](https://www.luogu.com.cn/problem/P1541)[代码](https://www.luogu.com.cn/paste/1pj8hgal)## 区间动态规划[P1775 石子合并(弱化版)](https://www.luogu.com.cn/problem/P1775)[代码](https://www.luogu.com.cn/paste/1zi86m9l)[P1140 相似基因](https://www.luogu.com.cn/problem/P1140)[代码](https://www.luogu.com.cn/paste/7f35ubdo)[CF607B Zuma](https://www.luogu.com.cn/problem/CF607B)[代码](https://www.luogu.com.cn/paste/tv5holbu)### 环形动态规划[P1880 [NOI1995] 石子合并](https://www.luogu.com.cn/problem/P1880)[代码](https://www.luogu.com.cn/paste/jurh56fc)[P1063 [NOIP 2006 提高组] 能量项链](https://www.luogu.com.cn/problem/P1063)[代码](https://www.luogu.com.cn/paste/5cspkxw2)# 并查集[P1551 亲戚](https://www.luogu.com.cn/problem/P1551)[代码](https://www.luogu.com.cn/paste/nwvs4jny)[P2024 [NOI2001] 食物链](https://www.luogu.com.cn/problem/P2024)[代码](https://www.luogu.com.cn/paste/rx7fxoxj)# 最小生成树[P3366 【模板】最小生成树](https://www.luogu.com.cn/problem/P3366)[代码](https://www.luogu.com.cn/paste/rup1p77k)# 最短路[P4779 【模板】单源最短路径(标准版)](https://www.luogu.com.cn/problem/P4779)[代码](https://www.luogu.com.cn/paste/mmtsbzg7)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395# 搜索## DFS- [ ] [P1731 [NOI1999] 生日蛋糕](https://www.luogu.com.cn/problem/P1731)[代码](https://www.luogu.com.cn/paste/yk3e2l90)- [ ] [UVA529 Addition Chains](https://www.luogu.com.cn/problem/UVA529)[代码](https://www.luogu.com.cn/paste/s4fdufx5)- [ ] [P4799 [CEOI 2015] 世界冰球锦标赛 (Day2)](https://www.luogu.com.cn/problem/P4799)[代码](https://www.luogu.com.cn/paste/9s7focc6)- [ ] [P1156 垃圾陷阱](https://www.luogu.com.cn/problem/P1156)[代码](https://www.luogu.com.cn/paste/qteyqb1i)- [ ] [P1004 [NOIP 2000 提高组] 方格取数](https://www.luogu.com.cn/problem/P1004)[代码](https://www.luogu.com.cn/paste/hdiordle)- [ ] [P1541 [NOIP 2010 提高组] 乌龟棋](https://www.luogu.com.cn/problem/P1541)[代码](https://www.luogu.com.cn/paste/kmdbeb6i)## BFS- [ ] [P1379 八数码难题](https://www.luogu.com.cn/problem/P1379)[代码](https://www.luogu.com.cn/paste/ga0ehl8z)- [ ] [P1551 亲戚](https://www.luogu.com.cn/problem/P1551)[代码](https://www.luogu.com.cn/paste/kvld5414)# 快速幂与矩阵乘法**详见[备忘录](https://www.luogu.com.cn/article/ksz69158)**- [ ] [P1226 【模板】快速幂](https://www.luogu.com.cn/problem/P1226)[代码](https://www.luogu.com.cn/paste/8qcp493d)- [ ] [P3390 【模板】矩阵快速幂](https://www.luogu.com.cn/problem/P3390)[代码](https://www.luogu.com.cn/paste/czvebnn2)- [ ] [P1962 斐波那契数列](https://www.luogu.com.cn/problem/P1962)[代码](https://www.luogu.com.cn/paste/e5dw731s)- [ ] [P1939 矩阵加速(数列)](https://www.luogu.com.cn/problem/P1939)[代码](https://www.luogu.com.cn/paste/0x4vhku2)# 字符串## 哈希- [ ] [P3370 【模板】字符串哈希](https://www.luogu.com.cn/problem/P3370)[代码](https://www.luogu.com.cn/paste/47mwjwue)## KMP**KMP算法是一种字符串匹配算法,它利用模式串自身的结构信息,在匹配失败时,不需要将搜索指针回溯,从而将时间复杂度从暴力算法的 $O(nm)$ 降低到 $O(n+m)$ 的算法。**- [ ] [P3375 【模板】KMP](https://www.luogu.com.cn/problem/P3375)[代码](https://www.luogu.com.cn/paste/qqjqwhef)## 字典树(Tire树)**字典树是一种多叉树结构,专门用于高效地存储和查找一组字符串。其基本思想是:用字符串的公共前缀来减少查询时间,最大限度地减少无谓的字符串比较。**- [ ] [P8306 【模板】字典树 / Trie](https://www.luogu.com.cn/problem/P8306)[代码](https://www.luogu.com.cn/paste/oixa14hl)## Manacher算法**Manacher算法是一种用于在一个字符串中查找所有回文子串,特别是最长回文子串的高效算法。它利用回文的对称性,避免了对每个中心进行重复的扩展匹配,从而将时间复杂度从暴力法的 $O(n²)$ 优化到 $O(n)$。**- [ ] [P3805 【模板】Manacher](https://www.luogu.com.cn/problem/P3805)[代码](https://www.luogu.com.cn/paste/yqs5yffd)- [ ] [P4555 [国家集训队] 最长双回文串](https://www.luogu.com.cn/problem/P4555)[代码](https://www.luogu.com.cn/paste/wft0dpbt)# 前缀和- [ ] [P8218 【深进1.例1】求区间和——【一维前缀和模板】](https://www.luogu.com.cn/problem/P8218)[代码](https://www.luogu.com.cn/paste/6dfwubjm)- [ ] [P1719 最大加权矩形——【二维前缀和模板】](https://www.luogu.com.cn/problem/P1719)[代码](https://www.luogu.com.cn/paste/n7t9i7ep)- [ ] [P1314 [NOIP 2011 提高组] 聪明的质监员](https://www.luogu.com.cn/problem/P1314)[代码](https://www.luogu.com.cn/paste/gjv1tapk)# 差分- [ ] [P2367 语文成绩——【差分模板】](https://www.luogu.com.cn/problem/P2367)[代码](https://www.luogu.com.cn/paste/58gvff49)- [ ] [P3397 地毯——【二维差分】](https://www.luogu.com.cn/problem/P3397)[代码](https://www.luogu.com.cn/paste/tf9054e7)# 离散化- [ ] [P1496 火烧赤壁——【离散化模板】](https://www.luogu.com.cn/problem/P1496)[代码](https://www.luogu.com.cn/paste/pzq0lxk8)- [ ] [P1884 [USACO12FEB] Overplanting S——【二维离散化】](https://www.luogu.com.cn/problem/P1884)[代码](https://www.luogu.com.cn/paste/i412nsed)- [ ] [P1904 天际线](https://www.luogu.com.cn/problem/P1904)[代码](https://www.luogu.com.cn/paste/6k5kbhhw)# 稀疏表(ST表)- [ ] [P3865 【模板】ST 表 && RMQ 问题](https://www.luogu.com.cn/problem/P3865)[代码](https://www.luogu.com.cn/paste/wczgxsuo)- [ ] [P2880 [USACO07JAN] Balanced Lineup G——【双ST表】](https://www.luogu.com.cn/problem/P2880)[代码](https://www.luogu.com.cn/paste/ev6ejfvn)- [ ] [P7333 [JRKSJ R1] JFCA](https://www.luogu.com.cn/problem/P7333)[代码](https://www.luogu.com.cn/paste/9lhxbcvh)- [ ] [P8818 [CSP-S 2022] 策略游戏](https://www.luogu.com.cn/problem/P8818)[代码](https://www.luogu.com.cn/paste/nxanxd4m)# 堆- [ ] [堆排序代码](https://www.luogu.com.cn/paste/ym92sdyq)- [ ] [P1801 黑匣子](https://www.luogu.com.cn/problem/P1801)[代码](https://www.luogu.com.cn/paste/wc0szb3h)- [ ] [P2085 最小函数值](https://www.luogu.com.cn/problem/P2085)[代码](https://www.luogu.com.cn/paste/irsluzft)# 树状数组- [ ] [P3374 【模板】树状数组 1](https://www.luogu.com.cn/problem/P3374)[代码](https://www.luogu.com.cn/paste/mx4rvxl6)- [ ] [P3368 【模板】树状数组 2](https://www.luogu.com.cn/problem/P3368)[代码](https://www.luogu.com.cn/paste/ogtraoeo)- [ ] [P1908 逆序对](https://www.luogu.com.cn/problem/P1908)[代码](https://www.luogu.com.cn/paste/lbe11o30)# 线段树- [ ] [P3372 【模板】线段树 1](https://www.luogu.com.cn/problem/P3372)[代码](https://www.luogu.com.cn/paste/wez36t8w)- [ ] [P2357 守墓人](https://www.luogu.com.cn/problem/P2357)[代码](https://www.luogu.com.cn/paste/n8cewdl0)- [ ] [P1253 扶苏的问题](https://www.luogu.com.cn/problem/P1253)[代码](https://www.luogu.com.cn/paste/lrd1304m)- [ ] [P3373 【模板】线段树 2](https://www.luogu.com.cn/problem/P3373)[代码](https://www.luogu.com.cn/paste/x7q7esky)- [ ] [P1438 无聊的数列](https://www.luogu.com.cn/problem/P1438)[代码](https://www.luogu.com.cn/paste/ljsg3q0v)# 分块- [ ] [P2357 守墓人](https://www.luogu.com.cn/problem/P2357)[代码](https://www.luogu.com.cn/paste/akzjpk22)# 排序- [ ] [P1080 [NOIP 2012 提高组] 国王游戏](https://www.luogu.com.cn/problem/P1080)[代码](https://www.luogu.com.cn/paste/t5e2hszl)## 归并排序- [ ] [P1908 逆序对](https://www.luogu.com.cn/problem/P1908)[代码](https://www.luogu.com.cn/paste/7dsm4jk6)## 拓扑排序- [ ] [B3644 【模板】拓扑排序 / 家谱树](https://www.luogu.com.cn/problem/B3644)[代码](https://www.luogu.com.cn/paste/m8naa09b)- [ ] [P1807 最长路](https://www.luogu.com.cn/problem/P1807)[代码](https://www.luogu.com.cn/paste/vzqia5q5)# 树**定义:****树的重心:树的重心指树中的一个节点,使得删去该节点后,剩下的各个连通分量的节点数最大值最小。****树的直径:树的直径指树中任意两个节点之间最长路径的长度。**- [ ] [P5908 猫猫和企鹅](https://www.luogu.com.cn/problem/P5908)[代码](https://www.luogu.com.cn/paste/91dfbmqj)- [ ] [P1395 会议——【树的重心模板】](https://www.luogu.com.cn/problem/P1395)[代码](https://www.luogu.com.cn/paste/y1vwwoxp)- [ ] [B4016 树的直径——【树的直径模板】](https://www.luogu.com.cn/problem/B4016)[代码](https://www.luogu.com.cn/paste/rmbmj9ux)- [ ] [P3379 【模板】最近公共祖先(LCA)](https://www.luogu.com.cn/problem/P3379)[代码](https://luogu.com.cn/paste/af38j9um)- [ ] [P2052 [NOI2011] 道路修建](https://www.luogu.com.cn/problem/P2052)[代码](https://www.luogu.com.cn/paste/ejbls0hh)- [ ] [P1351 [NOIP 2014 提高组] 联合权值](https://www.luogu.com.cn/problem/P1351)[代码](https://www.luogu.com.cn/paste/y415bfh8)- [ ] [P3128 [USACO15DEC] Max Flow P——【点树上差分】](https://www.luogu.com.cn/problem/P3128)[代码](https://www.luogu.com.cn/paste/l9das1ms)- [ ] [P6869 [COCI 2019/2020 #5] Putovanje——【边树上差分】](https://www.luogu.com.cn/problem/P6869)[代码](https://www.luogu.com.cn/paste/gtxsqy9n)- [ ] [P5536 【XR-3】核心城市](https://www.luogu.com.cn/problem/P5536)[代码](https://www.luogu.com.cn/paste/c1lwkf5a)# 动态规划## 背包问题- [ ] [P1048 [NOIP 2005 普及组] 采药——【01背包】](https://www.luogu.com.cn/problem/P1048)[代码](https://www.luogu.com.cn/paste/3z1xj9pt)- [ ] [P1616 疯狂的采药——【完全背包】](https://www.luogu.com.cn/problem/P1616)[代码](https://www.luogu.com.cn/paste/lllx48k9)- [ ] [P1776 宝物筛选——【多重背包】](https://www.luogu.com.cn/problem/P1776)[代码](https://www.luogu.com.cn/paste/ilo023rc)- [ ] [P1757 通天之分组背包——【分组背包】](https://www.luogu.com.cn/problem/P1757)[代码](https://www.luogu.com.cn/paste/84l7l6il)- [ ] [P2015 二叉苹果树——【树上背包】](https://www.luogu.com.cn/problem/P2015)[代码](https://www.luogu.com.cn/paste/c1yq9nc5)- [ ] [P1064 [NOIP 2006 提高组] 金明的预算方案](https://www.luogu.com.cn/problem/P1064)[代码](https://www.luogu.com.cn/paste/kc63da4v)- [ ] [P1156 垃圾陷阱](https://www.luogu.com.cn/problem/P1156)[代码](https://www.luogu.com.cn/paste/2g7m0jd4)## 线性动态规划- [ ] [B3637 最长上升子序列](https://www.luogu.com.cn/problem/B3637)[代码](https://www.luogu.com.cn/paste/8sq710aa)- [ ] [P2285 [HNOI2004] 打鼹鼠](https://www.luogu.com.cn/problem/P2285)[代码](https://www.luogu.com.cn/paste/tnk58bs4)- [ ] [P1020 [NOIP 1999 提高组] 导弹拦截](https://www.luogu.com.cn/problem/P1020)[代码【不优化做法】](https://www.luogu.com.cn/paste/xb1faasa)- [ ] [P1725 琪露诺](https://www.luogu.com.cn/problem/P1725)[代码](https://www.luogu.com.cn/paste/lrcvvpmi)- [ ] [P1439 【模板】最长公共子序列](https://www.luogu.com.cn/problem/P1439)[代码](https://www.luogu.com.cn/paste/nha8zqum)- [ ] [P1435 [IOI 2000] 回文字串](https://www.luogu.com.cn/problem/P1435)[代码](https://www.luogu.com.cn/paste/k4j5nzx2)- [ ] [P1004 [NOIP 2000 提高组] 方格取数](https://www.luogu.com.cn/problem/P1004)[代码](https://www.luogu.com.cn/paste/8ntaju99)- [ ] [P1541 [NOIP 2010 提高组] 乌龟棋](https://www.luogu.com.cn/problem/P1541)[代码](https://www.luogu.com.cn/paste/1pj8hgal)## 区间动态规划- [ ] [P1775 石子合并(弱化版)](https://www.luogu.com.cn/problem/P1775)[代码](https://www.luogu.com.cn/paste/1zi86m9l)- [ ] [P1140 相似基因](https://www.luogu.com.cn/problem/P1140)[代码](https://www.luogu.com.cn/paste/7f35ubdo)- [ ] [CF607B Zuma](https://www.luogu.com.cn/problem/CF607B)[代码](https://www.luogu.com.cn/paste/tv5holbu)### 环形动态规划- [ ] [P1880 [NOI1995] 石子合并](https://www.luogu.com.cn/problem/P1880)[代码](https://www.luogu.com.cn/paste/jurh56fc)- [ ] [P1063 [NOIP 2006 提高组] 能量项链](https://www.luogu.com.cn/problem/P1063)[代码](https://www.luogu.com.cn/paste/5cspkxw2)## 树形动态规划- [ ] [P1352 没有上司的舞会](https://www.luogu.com.cn/problem/P1352)[代码](https://www.luogu.com.cn/paste/klyrqg3q)## 状态压缩动态规划- [ ] [P1896 [SCOI2005] 互不侵犯](https://www.luogu.com.cn/problem/P1896)[代码](https://www.luogu.com.cn/paste/ciq5ia2b)- [ ] [P1433 吃奶酪](https://www.luogu.com.cn/problem/P1433)[代码](https://www.luogu.com.cn/paste/d7u68ce3)## 数位动态规划- [ ] [P2657 [SCOI2009] windy 数](https://www.luogu.com.cn/problem/P2657)[代码](https://www.luogu.com.cn/paste/gjxdz3ri)# 并查集- [ ] [P1551 亲戚](https://www.luogu.com.cn/problem/P1551)[代码](https://www.luogu.com.cn/paste/nwvs4jny)- [ ] [P2024 [NOI2001] 食物链](https://www.luogu.com.cn/problem/P2024)[代码](https://www.luogu.com.cn/paste/rx7fxoxj)# 最小生成树**定义:在一个带权无向连通图中,最小生成树是包含图中所有顶点的、边数最少的连通子图(即一棵树),且所有边的权重之和最小。**- [ ] [P3366 【模板】最小生成树](https://www.luogu.com.cn/problem/P3366)[代码](https://www.luogu.com.cn/paste/rup1p77k)# 最短路**关于负环:在一个有向图(或无向图)中,如果一个环(回路)上所有边的边权之和为负数,那么这个环就叫做负环。**在SPFA等算法中,可能需要判断是否存在负环,而判断的方法就是若一个点进入了**松弛队列**超过 $n$ 次的话,那该点一定在一个负环。因为**在一个没有负环的图中,任意两个点之间的最短路径最多包含 $n-1$ 条边**,而当有条最短路包含了 $n$ 条及以上的边,则证明该路径存在环,而既然包含环的话就**代表该环是负环能让距离变短**。**因为每次松弛操作都会使路径增加一,所以一个点进入了松弛队列超过 $n$ 次,就说明一定存在一条边数大于 $n$ 的最短路,也就是存在负环。**故 `if(++all[id]>=n+1)return false;`。- [ ] [B3647 【模板】Floyd](https://www.luogu.com.cn/problem/B3647)[代码](https://www.luogu.com.cn/paste/aqbhc1rr)- [ ] [P2910 [USACO08OPEN] Clear And Present Danger S](https://www.luogu.com.cn/problem/P2910)[代码](https://www.luogu.com.cn/paste/24drxi6x)- [ ] [P3371 【模板】单源最短路径(弱化版)](https://www.luogu.com.cn/problem/P3371)[代码(Bellman–Ford和SPFA做法)](https://www.luogu.com.cn/paste/is0hawq2)- [ ] [P4779 【模板】单源最短路径(标准版)](https://www.luogu.com.cn/problem/P4779)[代码(Dijkstra做法)](https://www.luogu.com.cn/paste/mmtsbzg7)## 差分约束**定义:差分约束系统指由多个形如 $x_i-x_j≤c_k$ 的不等式组成的不等式组。其中 $xᵢ$,$xⱼ$ 是变量,$c_k$ 是常数,求解的目标是找到一组满足所有不等式的变量值。**因为不等式的性质,我们可以把不等式变形:$$$x_i-x_j≤c \Rightarrow x_i ≤ x_j + c$$$我们发现最短路中对于图中的一条边 $u \rightarrow v$,权值为 $w$,最短路完成后一定有:$$$dis[v]≤dis[u]+w$$$所以我们可以用这些信息建图:- 将每个变量 $x_i$ 抽象为图中的一个顶点;- 将每个不等式 $x_i-x_j≤c_k$ 抽象为一条从 $j$ 到 $i$ 的边权为 $c_k$;- 最后跑遍最短路,每个 $dis[i]$ 就是一组满足条件的解了。但是,图可能不连通,某些节点无法从源点到达。所以我们要加一个超级原点,即从 $0$ 向所有节点连一条权值为 $0$ 的边。所以这样就能保证所有节点从 $0$ 出发都能到达以便更新答案。当然,当不等式的不等号反过来就是求最长路了,同理。- [ ] [P5960 【模板】差分约束](https://www.luogu.com.cn/problem/P5960)[代码](https://www.luogu.com.cn/paste/gvonsim7)- [ ] [P1993 小 K 的农场](https://www.luogu.com.cn/problem/P1993)[代码](https://www.luogu.com.cn/paste/rxxb0rn6)# 次短路- [ ] [P2865 [USACO06NOV] Roadblocks G](https://www.luogu.com.cn/problem/P2865)[代码](https://www.luogu.com.cn/paste/jnkl8ae9)# 强连通分量**定义:在有向图中满足“任意两点互相可达”这一条件的极大顶点集合为强连通分量。**- [ ] [P3387 【模板】缩点 / 强连通分量](https://www.luogu.com.cn/problem/P3387)[代码](https://www.luogu.com.cn/paste/ljacm7w3)# 双连通分量**定义:边双连通分量:无向图中的一个极大边集,使得删除集合内任意一条边后,剩余的部分仍然连通,则该边集为边双连通分量,即使得子图边集内任意一条边都位于某一个简单环上。****点双连通分量:无向图中的一个极大顶点集合,使得删除集合内任意一个顶点后,剩余部分仍然连通,则该点集为双连通分量,即使得集合内任意两条边都位于同一个简单环上。**- [ ] [P8436 【模板】边双连通分量](https://www.luogu.com.cn/problem/P8436)[代码](https://www.luogu.com.cn/paste/9zodj7ux)- [ ] [P8435 【模板】点双连通分量](https://www.luogu.com.cn/problem/P8435)[代码](https://www.luogu.com.cn/paste/dp8a72ij)# 割点与桥**定义:****割点:在一个无向连通图中,如果删除某个顶点及其关联的所有边后,图变得不再连通,那么这个顶点被称为割点。****桥:在一个无向连通图中,如果删除某条边后,图变得不再连通,那么这条边被称为桥(也叫割边)。**- [ ] [P3388 【模板】割点(割顶)](https://www.luogu.com.cn/problem/P3388)[代码](https://www.luogu.com.cn/paste/0rydcjb4)- [ ] [P1656 炸铁路——【桥模板】](https://www.luogu.com.cn/problem/P1656)[代码](https://www.luogu.com.cn/paste/kccoxepj)# 二分图判定与匹配**定义:如果一个无向图的所有顶点可以被分成两个互不相交的非空集合 $U$ 和 $V$,使得图中的每一条边都连接着 $U$ 中的一个顶点和 $V$ 中的一个顶点(即集合内部的顶点之间没有边相连),那么这个图就是二分图。**- [ ] [P1330 封锁阳光大学——【二分图的判定】](https://www.luogu.com.cn/problem/P1330)[代码](https://www.luogu.com.cn/paste/83f4me1w)- [ ] [P3386 【模板】二分图最大匹配](https://www.luogu.com.cn/problem/P3386)[代码](https://www.luogu.com.cn/paste/yd6m1y3q)# 欧拉路径**定义:在连通图中,经过图中每一条边恰好一次的路径,称为欧拉路径。如果这条路径最终能回到起点,也就是起点和终点相同,则称为欧拉回路。**- [ ] [P1333 瑞瑞的木棍——【判断欧拉路径】](https://www.luogu.com.cn/problem/P1333)[代码](https://www.luogu.com.cn/paste/13aqvkoz)- [ ] [P7771 【模板】欧拉路径](https://www.luogu.com.cn/problem/P7771)[代码](https://www.luogu.com.cn/paste/uih5wmju)- [ ] [P2731 [USACO3.3] 骑马修栅栏 Riding the Fences](https://www.luogu.com.cn/problem/P2731)[代码](https://www.luogu.com.cn/paste/nep30zdy)# 树链剖分- [ ] [P3384 【模板】重链剖分 / 树链剖分](https://www.luogu.com.cn/problem/P3384)[代码](https://www.luogu.com.cn/paste/pzm9mgkq)- [ ] [P2486 [SDOI2011] 染色](https://www.luogu.com.cn/problem/P2486)[代码](https://www.luogu.com.cn/paste/bg471dfr)- [ ] [P1505 [国家集训队] 旅游——【边操作】](https://www.luogu.com.cn/problem/P1505)[代码](https://www.luogu.com.cn/paste/znens2xp)- [ ] [P2146 [NOI2015] 软件包管理器](https://www.luogu.com.cn/problem/P2146)[代码](https://www.luogu.com.cn/paste/1f73dn2o)# 扫描线- [ ] [P5490 【模板】扫描线 & 矩形面积并](https://www.luogu.com.cn/problem/P5490)[代码](https://www.luogu.com.cn/paste/8rq24byb)