版本比较
入门DP+贪心杂题
正文
增加 2 行删除 0 行
11 行未改动12131415161711 行未改动$f$:新的答案有 $u$,$v$ 本身的答案,$u$ 中集合每个与 $v$ 中集合合并的贡献。则 $f_u=f_u+f_v+f_u\times g_v+f_v\times f_u$。[code](https://www.luogu.com.cn/record/291351527)。
### [P13957 [ICPC 2023 Nanjing R] 背包](https://www.luogu.com.cn/problem/P13957)直接暴力DP是 $O(nkW)$ 的,无法通过。考虑先贪心。此时有两种策略:免费选价值最大和体积最大的。后者是[正确](https://www.luogu.com.cn/discuss/1260205)的,所以先按体积排序,每次对一个前缀做 01 背包,并对后缀选出价值最大的即可。[code](https://www.luogu.com.cn/record/291554926)。### [P3554 [POI 2013] LUK-Triumphal arch](https://www.luogu.com.cn/problem/P3554)没想到状态。设 $dp_i$ 表示 $i$ 子树内(不包含 $i$)需要染多少个点,先二分 $k$,则有转移:$dp_i=\max(0,\sum (dp_v+1) -k)$。每次判断 $dp_1$ 即可。[code](https://www.luogu.com.cn/record/292069372)。