$\DeclareMathOperator{\sw}{sw}$ $\DeclareMathOperator{\sb}{sb}$ $\DeclareMathOperator{\dp}{dp}$ 用 $\sw[i]$ 表示前 $i$ 個盒子中全部白盒子的權值之和。 用 $\sb[i]$ 表示前 $i$ 個盒子中全部黑盒子的權值之和。app
對於偶數 $i$,用 $\dp[i]$ 表示此白盒子以前的全部盒子是否存在合法劃分。this
轉移方程
$\dp[i] = \mathsf{true} \iff$ 存在偶數 $j < i$ 知足 $\dp[j] = \mathsf{true}$ 且 $\sb[i-1] - \sb[j] - (\sw[i-1] - \sw[j]) \ge X$ 。url
注意到,$ \sb[i-1] - \sb[j] - (\sw[i-1] - \sw[j]) \ge X $ 即 $ (\sb[i-1] - \sw[i-1]) - (\sb[j] - \sw[j]) $ 。spa
題解上所說的.net
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.code
能夠這樣理解:遊戲
先手玩家能夠事先從左到右任選 $k$ 個白盒子(即上圖中的圓形)這些白盒子將餘下的盒子分紅 $k+1$ 段(即上圖中的矩形,當總共有奇數個盒子時,最後一段多是空的)。不管後手玩家如何應對,先手玩家總能夠在最後一個階段取走這 $k+1$ 段中某一段裏的全部黑色盒子而結束遊戲,而讓先手玩家最後取走哪一段裏的全部黑盒子徹底由後手玩家肯定。ci
有一種特殊狀況須要注意:當 $n$ 爲偶數時,若先手玩家在某一步拿走了最後一個白盒子,那麼先手玩家的「最後一個階段」只能是「取走最後一個白盒子以後的空段裏的黑盒子」而不能是「取走最後一個白盒子以前的某一段裏的全部黑盒子」,在這種狀況下,先手玩家在最後一個階段的行爲是由先手玩家本身決定的,而不是由後手玩家決定的。事實上,若是先手玩家取了最後一個白盒子,那麼他必然取走了所有白盒子然後手玩家取走了所有黑盒子。get
因此最好是對 $n$ 爲偶數的狀況單獨處理,這種狀況下先手的策略是:取所有黑盒子或所有白盒子。it