树上dp
JohnJoeZhu
·
·
个人记录
我居然没有总结过?! 吓死我了
讲解
树形dp讲解
树上dp入门及习题
树形背包
习题
直接dp
结论:一个序列的子序列的合法括号序列个数
sum[i]=sum[i-1]+$以当前位置为结尾的合法括号序列的个数$g[i]
- [P4395 [BOI2003]Gem 气垫车](https://www.luogu.com.cn/problem/P4395)
- [P2585 [ZJOI2006]三色二叉树](https://www.luogu.com.cn/problem/P2585)
树上染色:颜色个数较少,可以开一维统计
- [P1040 加分二叉树](https://www.luogu.com.cn/problem/P1040)
- [P1122 最大子树和](https://www.luogu.com.cn/problem/P1122)
- [P3698 [CQOI2017]小Q的棋盘](https://www.luogu.com.cn/problem/P3698) [题解](https://www.luogu.com.cn/blog/xzy/solution-p3698)
- [P3174 [HAOI2009]毛毛虫](https://www.luogu.com.cn/problem/P3174) 自带题解~~好评~~
- [P1272 重建道路](https://www.luogu.com.cn/problem/P1272) [题解](https://www.luogu.com.cn/blog/wojiaoheavensheep/solution-p1272) 好题(但我不会
- [P3354 [IOI2005]Riv 河流](https://www.luogu.com.cn/problem/P3354)
##### 树上背包
- [P3177 [HAOI2015]树上染色](https://www.luogu.com.cn/problem/P3177)
- [P1064 金明的预算方案](https://www.luogu.com.cn/problem/P1064)
- [P1270 “访问”美术馆](https://www.luogu.com.cn/problem/P1270)
- [P3360 偷天换日](https://www.luogu.com.cn/problem/P3360)
##### 基环树dp
- [P1453 城市环路](https://www.luogu.com.cn/problem/P1453) 基环树dp
- [P2607 [ZJOI2008]骑士](https://www.luogu.com.cn/problem/P2607) 同为基环树dp
- [P1399 [NOI2013]快餐店](https://www.luogu.com.cn/problem/P1399)
- [P4381 [IOI2008]Island](https://www.luogu.com.cn/problem/P4381) 基环树+直径+单调队列优化dp
- [P2081 [NOI2012] 迷失游乐园
](https://www.luogu.com.cn/problem/P2081) 基环树+期望dp
##### 换根dp
思路:求根节点的值,再转移即可
转移方式:画出$u->v$及$u$和$v$的第一层子树,分析即可
- [P3047 [USACO12FEB]Nearby Cows G](https://www.luogu.com.cn/problem/P3047)
- [CF1187E Tree Painting
](https://www.luogu.com.cn/problem/CF1187E)
- [P2986 [USACO10MAR]Great Cow Gathering G](https://www.luogu.com.cn/problem/P2986)
话说,有时候你以为的换根dp,实际上是换个状态记录就好了(就是记录终点的技巧之类的)