Array
1563. Stone Game V
The score Alice can bank from any stretch of stones depends only on that stretch, so I memoize on intervals: dp[i][j] is the most she can score starting from stones i..j. Each turn she picks a cut, Bob throws away the heavier side, and she keeps playing on whatever survives — and the survivor is always contiguous, which is exactly what lets memoization work.
Loading…