随笔分类 -  区间 dp

摘要:洛谷传送门 CF 传送门 虚高 *2800。放模拟赛 T2 人均切了。 考虑拎出环上的点,每个点下面都挂了一棵树。 那么可以预处理出每棵树从一个点开始染黑,这棵树对答案的贡献。因为一棵树染了一个点就只能去染子树了,所以这个贡献是固定的,用换根 dp 求即可。 那么我们现在可以在环上选择一个起点,每次 阅读全文
posted @ 2024-01-23 11:29 zltzlt 阅读(15) 评论(0) 推荐(0)
摘要:[洛谷传送门](https://www.luogu.com.cn/problem/CF888F "洛谷传送门") [CF 传送门](https://codeforces.com/problemset/problem/888/F "CF 传送门") 做做简单题放松身心。 考虑区间 dp,设 $f_{i 阅读全文
posted @ 2023-07-31 23:30 zltzlt 阅读(32) 评论(0) 推荐(0)
摘要:[洛谷传送门](https://www.luogu.com.cn/problem/AT_keyence2021_e "洛谷传送门") [AtCoder 传送门](https://atcoder.jp/contests/keyence2021/tasks/keyence2021_e "AtCoder 阅读全文
posted @ 2023-07-06 16:18 zltzlt 阅读(25) 评论(0) 推荐(0)
摘要:[洛谷传送门](https://www.luogu.com.cn/problem/AT_arc153_e "洛谷传送门") [AtCoder 传送门](https://atcoder.jp/contests/arc153/tasks/arc153_e "AtCoder 传送门") 我们考虑给定 $X 阅读全文
posted @ 2023-07-03 21:05 zltzlt 阅读(34) 评论(0) 推荐(0)
摘要:[洛谷传送门](https://www.luogu.com.cn/problem/AT_abc238_h "洛谷传送门") [AtCoder 传送门](https://atcoder.jp/contests/abc238/tasks/abc238_h "AtCoder 传送门") 考虑期望转计数,方 阅读全文
posted @ 2023-06-27 13:34 zltzlt 阅读(64) 评论(0) 推荐(0)
摘要:[洛谷传送门](https://www.luogu.com.cn/problem/AT_abc219_h "洛谷传送门") [AtCoder 传送门](https://atcoder.jp/contests/abc219/tasks/abc219_h "AtCoder 传送门") 套路化了。 比较显 阅读全文
posted @ 2023-06-14 21:47 zltzlt 阅读(42) 评论(0) 推荐(0)
摘要:[洛谷传送门](https://www.luogu.com.cn/problem/AT_abc303_g "洛谷传送门") [AtCoder 传送门](https://atcoder.jp/contests/abc303/tasks/abc303_g "AtCoder 传送门") 经典题,考虑区间 阅读全文
posted @ 2023-05-28 19:19 zltzlt 阅读(134) 评论(0) 推荐(0)
摘要:[洛谷传送门](https://www.luogu.com.cn/problem/AT_agc062_b "洛谷传送门") [AtCoder 传送门](https://atcoder.jp/contests/agc062/tasks/agc062_b "AtCoder 传送门") 妙妙题。 像这种最 阅读全文
posted @ 2023-05-22 10:50 zltzlt 阅读(48) 评论(0) 推荐(0)
摘要:洛谷传送门 AtCoder 传送门 考虑连边 $(i,p_i)$(若 $p_i = -1$ 则不连边),可以发现形成了一篇内向树森林且这个森林存在一个 dfs 序为 $1,2,...,n$。 这棵森林有如下性质: $\forall v \in son_u,h_u > h_v$ $\forall v, 阅读全文
posted @ 2023-04-16 09:57 zltzlt 阅读(21) 评论(0) 推荐(0)
该文被密码保护。
posted @ 2022-07-15 16:41 zltzlt 阅读(1) 评论(0) 推荐(0)
摘要:洛谷传送门 CF 传送门 思路 考虑区间 dp。设 $f_{i,j}$ 为只考虑区间 $[l,r]$ 的点的最小值。转移就考虑计算每条边的贡献,枚举根,则根到左子树的这条边的贡献即为左子树的点为 $i$,非左子树的点为 $j$ 的所有 $c_{i,j}$ 的和。右子树同理。二维前缀和预处理一下即可做 阅读全文
posted @ 2022-07-13 21:12 zltzlt 阅读(121) 评论(0) 推荐(0)
摘要:洛谷传送门 思路 区间 dp。设 \(f_{l,r}\) 为子串 \([l,r]\) 压缩的最短长度,显然有 \(f_{l,r} \gets \min\limits_{i=l}^{r-1} f_{l,i} + f_{i+1,r}\)。还要考虑压缩 \([l,r]\) 的情况。 设 \(fail_{i 阅读全文
posted @ 2022-06-22 11:00 zltzlt 阅读(54) 评论(0) 推荐(0)