AGC 26 F Manju Game

$\DeclareMathOperator{\sw}{sw}$
$\DeclareMathOperator{\sb}{sb}$
$\DeclareMathOperator{\dp}{dp}$
用 $\sw[i]$ 表示前 $i$ 个盒子中所有白盒子的权值之和。
用 $\sb[i]$ 表示前 $i$ 个盒子中所有黑盒子的权值之和。

对于偶数 $i$,用 $\dp[i]$ 表示此白盒子之前的所有盒子是否存在合法划分。

转移方程

$\dp[i] = \mathsf{true} \iff$ 存在偶数 $j < i$ 满足 $\dp[j] = \mathsf{true}$ 且 $\sb[i-1] - \sb[j] - (\sw[i-1] - \sw[j]) \ge X$ 。

注意到,$ \sb[i-1] - \sb[j] - (\sw[i-1] - \sw[j]) \ge X $ 即 $ (\sb[i-1] - \sw[i-1]) - (\sb[j] - \sw[j]) $ 。

思路示意图

题解上所说的

Let $W_1, \dots , W_k$ be the white boxes that appear in this tree, from left to right. The first player will take all these boxes, no matter what the second player does. These $k$ boxes split the sequence of boxes into $k + 1$ parts. For one of these parts, the first player takes all black boxes and the second player takes all white boxes. For all other parts, the first player takes all white boxes and the second player takes all black boxes. The choice of the "one part" depends on the second player’s strategy.

可以这样理解:

先手玩家可以事先从左到右任选 $k$ 个白盒子(即上图中的圆形)这些白盒子将余下的盒子分成 $k+1$ 段(即上图中的矩形,当总共有奇数个盒子时,最后一段可能是空的)。无论后手玩家如何应对,先手玩家总可以在最后一个阶段取走这 $k+1$ 段中某一段里的所有黑色盒子而结束游戏,而让先手玩家最后取走哪一段里的所有黑盒子完全由后手玩家确定。

有一种特殊情况需要注意:当 $n$ 为偶数时,若先手玩家在某一步拿走了最后一个白盒子,那么先手玩家的「最后一个阶段」只能是「取走最后一个白盒子之后的空段里的黑盒子」而不能是「取走最后一个白盒子之前的某一段里的所有黑盒子」,在这种情况下,先手玩家在最后一个阶段的行为是由先手玩家自己决定的,而不是由后手玩家决定的。事实上,如果先手玩家取了最后一个白盒子,那么他必然取走了全部白盒子而后手玩家取走了全部黑盒子。

所以最好是对 $n$ 为偶数的情况单独处理,这种情况下先手的策略是:取全部黑盒子或全部白盒子。

扫描二维码关注公众号,回复: 2302685 查看本文章

猜你喜欢

转载自www.cnblogs.com/Patt/p/9335285.html