Stone Game
Alex and Lee play a game with piles of stones. There are an even number of pilesarranged in a row, and each pile has a positive integer number of stonespiles[i]
.
The objective of the game is to end with the most stones. The total number of stones is odd, so there are no ties.
Alex and Lee take turns, with Alex starting first. Each turn, a player takes the entire pile of stones from either the beginning or the end of the row. This continues until there are no more piles left, at which point the person with the most stones wins.
Assuming Alex and Lee play optimally, returnTrue
if and only if Alex wins the game.
Example 1:
Note:
分析
因为是两头都能取,所以需要i,j记录,所以只能一个头的话,就一维数组
dp[i][j] = sum[i][j] - min(dp[i+1][j],dp[i][j-1])
Last updated