版本比较
题解:P12494 [集训队互测 2024] 数位 DP
正文
增加 2 行删除 2 行
12345456789119 行未改动全部展开结论:每次能得到的 $m$ 一定是一段前缀 $[0, x]$。
归纳证明:1. 如果当前的操作是 $\texttt{and}$,$x\gets min(x, c)$。2. 如果当前的操作是 $\texttt{or}$ 或 $\texttt{xor}$,$x\gets x \operatorname{or} c \operatorname{or} (2^{\operatorname{highbit}{(x\operatorname{and} c})}-1)$。容易发现 $or$ 和 $xor$ 是等价的。1. 如果当前的操作是 $\texttt{and}$,$x\gets \min(x, c)$。2. 如果当前的操作是 $\texttt{or}$ 或 $\texttt{xor}$,$x\gets x \operatorname{or} c \operatorname{or} (2^{\operatorname{highbit}{(x\operatorname{and} c})}-1)$。容易发现 $\texttt{or}$ 和 $\texttt{xor}$ 是等价的。
倒着考虑,我们已知操作完后的 $x$ 的最小值,求操作之前的 $x'$ 至少是多少。
1. $\texttt{and}$:要求 $c\ge x$,$x$ 不变,有方案数 $2^k-x$。119 行未改动全部展开