正文
增加 48 行删除 21 行
62 行未改动6364656667686970717273747576777879808182838485868788899091922 行未改动959697989910010110210362 行未改动16616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820978 行未改动28828929029129229329429529629729829930030130230325 行未改动3293303313323333343353363373385 行未改动34434534634734834935035135235335435535635735835936036136236336436536636736862 行未改动- [ ] [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)2 行未改动- [ ] [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)62 行未改动- [ ] [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)- [ ] [【边树上差分】——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)# 动态规划## 背包问题- [ ] [【01背包】——P1048 [NOIP 2005 普及组] 采药](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)78 行未改动因为**在一个没有负环的图中,任意两个点之间的最短路径最多包含 $n-1$ 条边**,而当有条最短路包含了 $n$ 条及以上的边,则证明该路径存在环,而既然包含环的话就**代表该环是负环能让距离变短**。**因为每次松弛操作都会使路径增加一,所以一个点进入了松弛队列超过 $n$ 次,就说明一定存在一条边数大于 $n$ 的最短路,也就是存在负环。**故 `if(++all[id]>=n+1)return false;`。- [ ] [【Floyd算法模板】——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)[代码](https://www.luogu.com.cn/paste/mmtsbzg7)## 差分约束**定义:差分约束系统指由多个形如 $x_i-x_j≤c_k$ 的不等式组成的不等式组。其中 $xᵢ$,$xⱼ$ 是变量,$c_k$ 是常数,求解的目标是找到一组满足所有不等式的变量值。**因为不等式的性质,我们可以把不等式变形:$$$25 行未改动- [ ] [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)5 行未改动- [ ] [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)62 行未改动6364656667686970717273747576777879808182838485868788899091922 行未改动959697989910010110210362 行未改动16616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121278 行未改动29129229329429529629729829930030130230330430530630730830925 行未改动3353363373383393403413423433443453463475 行未改动35335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439562 行未改动- [ ] [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)2 行未改动- [ ] [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)62 行未改动- [ ] [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)78 行未改动因为**在一个没有负环的图中,任意两个点之间的最短路径最多包含 $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$ 是常数,求解的目标是找到一组满足所有不等式的变量值。**因为不等式的性质,我们可以把不等式变形:$$$25 行未改动- [ ] [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)5 行未改动- [ ] [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)