随笔分类 - 背包
摘要:洛谷传送门 CF 传送门 放放/ll/ll/ll。 这题是个性质题。 首先第一排一定是升序,第二排一定是降序。考虑第一排若存在 \(i < j\) 使得 \(a_{1, i} > a_{1, j}\),那么交换这两个数不会变劣。第二排类似。 然后发现在 \(1\) 走下去或在 \(n\) 走下去最优
阅读全文
摘要:洛谷传送门 AtCoder 传送门 和 CF1010F Tree 基本一致。 考虑经典树形背包,设 \(f_{u, i}\) 为 \(u\) 子树内选了 \(i\) 个点的方案数。初始有 \(f_{u, 0} = 1\)。每次考虑合并儿子 \(v\),有转移: \[f_{u, i + j} \get
阅读全文
摘要:洛谷传送门 CF 传送门 educational 的。另一道类似的题是 [ABC269Ex] Antichain。 考虑令 \(b_u = a_u - \sum\limits_{v \in son_u} a_v\)。那么 \(\sum\limits_{i = 1}^n b_i = a_1 = x\)
阅读全文
摘要:洛谷传送门 CF 传送门 考虑形式化地描述这个问题。先把 \(l\) 排序。然后相当于是否存在一个 \(\{1, 2, \ldots, n\}\) 的子集 \(S\),使得: \(\sum\limits_{i \in S} l_i = d\)。 \(\exists T \subseteq S, \m
阅读全文
摘要:洛谷传送门 CF 传送门 考虑一条好的路径 \(x \to y\) 中一定至少存在一条边 \((u, v)\),满足这条边的序列 \(a\) 存在一个 \(j \in [1, |a| - 1]\),满足 \(a_j = u, a_{j + 1} = v\),就是说 \(a\) 包含一对相邻的 \((
阅读全文
摘要:LOJ 传送门 显然枚举物品做背包没有前途,于是我们把体积相等的物品捆绑在一起。 设 \(f_{i, j}\) 为考虑完体积 \(\in [1, i]\) 的物品,背包容量为 \(j\) 的最大值。可以贪心求出 \(g_{i, j}\) 为选 \(j\) 个体积为 \(i\) 的物品的价值最大值。
阅读全文
摘要:CF 传送门 发现物品的体积很小,尝试从此处入手。 设 \(K\) 为最大的物品体积。把背包体积 \(m\) 分成差不超过 \(K\) 的两部分,然后合并。这样需要求出 \(f(\frac{m}{2} - K \sim \frac{m}{2} + K)\)。 递归地,可以发现需要求出 \(f(\fr
阅读全文
摘要:洛谷传送门 AtCoder 传送门 人生中第一道 AtCoder 问号题。 设 \(P = 998244353\)。 注意到 \(f(T)\) 的定义式中,\(\frac{1}{n}\) 大概是启示我们转成概率去做。发现若把 \(\frac{1}{n}\) 换成 \(\frac{1}{n - 1}\
阅读全文
摘要:洛谷传送门 CF 传送门 典? 考虑枚举 \(r\),算有多少种方案使得,存在一个点,离它最近的黑点距离 \(> r\)。 设 \(f_{u, i}\) 为 \(u\) 子树内离 \(u\) 最近的黑点距离为 \(i\)。如果一个点子树中离它最近的黑点距离 \(> r\),那么它就已经满足子树的限制
阅读全文
摘要:[洛谷传送门](https://www.luogu.com.cn/problem/AT_agc041_f "洛谷传送门") [AtCoder 传送门](https://atcoder.jp/contests/agc041/tasks/agc041_f "AtCoder 传送门") 神题!!!!!!!
阅读全文
摘要:[洛谷传送门](https://www.luogu.com.cn/problem/CF1856E2 "洛谷传送门") [CF 传送门](https://codeforces.com/problemset/problem/1856/E2 "CF 传送门") 考虑局部贪心,假设我们现在在 $u$,我们希
阅读全文
摘要:[洛谷传送门](https://www.luogu.com.cn/problem/CF1856E1 "洛谷传送门") [CF 传送门](https://codeforces.com/problemset/problem/1856/E1 "CF 传送门") 考虑局部贪心,假设我们现在在 $u$,我们希
阅读全文
摘要:洛谷传送门 感觉跟 CF Gym 102978H Harsh Comments 很像。 考虑容斥,钦定 \(S \subseteq [2, n]\) 中的人比 \(1\) 后死。设 \(P(S)\) 为 \(S\) 中的人比 \(1\) 后死的概率,那么答案为: \[ans = \sum\limit
阅读全文
摘要:[洛谷传送门](https://www.luogu.com.cn/problem/AT_arc162_d "洛谷传送门") [AtCoder 传送门](https://atcoder.jp/contests/arc162/tasks/arc162_d "AtCoder 传送门") 注意到,如果给定每
阅读全文
摘要:[洛谷传送门](https://www.luogu.com.cn/problem/AT_abc235_h "洛谷传送门") [AtCoder 传送门](https://atcoder.jp/contests/abc235/tasks/abc235_h "AtCoder 传送门") 为啥洛谷唯一一篇题
阅读全文
摘要:[洛谷传送门](https://www.luogu.com.cn/problem/AT_abc221_g "洛谷传送门") [AtCoder 传送门](https://atcoder.jp/contests/abc221/tasks/abc221_g "AtCoder 传送门") 这个数据范围让我们
阅读全文
摘要:[洛谷传送门](https://www.luogu.com.cn/problem/CF1839E "洛谷传送门") [CF 传送门](https://codeforces.com/problemset/problem/1839/E "CF 传送门") 不会,不知道该如何评价。确实是自己的问题。 这种
阅读全文
摘要:[洛谷传送门](https://www.luogu.com.cn/problem/CF1830D "洛谷传送门") [CF 传送门](https://codeforces.com/contest/1830/problem/D "CF 传送门") 考虑答案的下界。 对整棵树进行二分图染色,我们得到答案
阅读全文
摘要:[洛谷传送门](https://www.luogu.com.cn/problem/AT_abc207_f "洛谷传送门") [AtCoder 传送门](https://atcoder.jp/contests/abc207/tasks/abc207_f "AtCoder 传送门") 简单树形 dp。
阅读全文
摘要:洛谷传送门 AtCoder 传送门 首先将度数 $-1$。 设 $f_i$ 为体积为 $i$ 至多能用几个物品凑出来,$g_i$ 为至少。 我们现在要证明一个东西:$x \in [g_i, f_i]$,$(i, x)$ 合法。 首先若 $(s, x)$ 合法,那么必须满足 $s - x \in [-
阅读全文

浙公网安备 33010602011771号