Array
1406. Stone Game III
Both players optimize, so I never track two separate scores — I track one number: the lead the player to move can force from each suffix. Define dp[i] as (mover's stones) − (opponent's stones) under optimal play starting at index i. Taking the first k stones (k in 1..3) hands the opponent the position i+k, where they in turn play optimally, so dp[i] = max over k of (sum of stoneValue[i..i+k-1] − dp[i+k]). The sign of dp[0] decides it: positive Alice, negative Bob, zero Tie.
Loading…