★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
➤ micro-channel public number: Shan Wing Chi ( shanqingyongzhi)
➤ blog Park address: San-ching Wing Chi ( https://www.cnblogs.com/strengthen/ )
➤GitHub address: https://github.com/strengthen/LeetCode
➤ original address: HTTPS: // the WWW. cnblogs.com/strengthen/p/11258434.html
➤ If the address is not a link blog Park Yong Shan Chi, it may be crawling author of the article.
➤ text has been modified update! Click strongly recommended that the original address read! Support authors! Support the original!
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
Alex and Lee continue their games with piles of stones. There are a number of piles arranged in a row, and each pile has a positive integer number of stones piles[i]
. The objective of the game is to end with the most stones.
Alex and Lee take turns, with Alex starting first. Initially, M = 1
.
On each player's turn, that player can take all the stones in the first X
remaining piles, where 1 <= X <= 2M
. Then, we set M = max(M, X)
.
The game continues until all the stones have been taken.
Assuming Alex and Lee play optimally, return the maximum number of stones Alex can get.
Example 1:
Input: piles = [2,7,9,4,4] Output: 10 Explanation: If Alex takes one pile at the beginning, Lee takes two piles, then Alex takes 2 piles again. Alex can get 2 + 4 + 4 = 10 piles in total. If Alex takes two piles at the beginning, then Lee can take all three piles left. In this case, Alex get 2 + 7 = 9 piles in total. So we return 10 since it's larger.
Constraints:
1 <= piles.length <= 100
1 <= piles[i] <= 10 ^ 4
Alex and Lee continue their game stones. Many pile of stones in a row, there is a positive integer pieces of stones each pile piles[i]
. Who's Got the game with the most stones to determine the winner.
Alex and Lee take turns, Alex first start. Initially,M = 1
.
In each player's turn, the player can take the rest of the former X
all heap of stones, which 1 <= X <= 2M
. Then make M = max(M, X)
.
The game continues until all the stones have been taken away.
Alex Lee assumptions and play the best level, returns the largest number of stone Alex can get.
Example:
Input: piles = [2,7,9,4,4] Output: 10 Explanation: If Alex took a pile of stones in the beginning, Lee took two piles, then Alex also took two piles . In this case, Alex can get 2 + 4 + 4 = 10 stones. If Alex took two piles of stones in the beginning, then Lee can take away all the remaining three groups of stones. In this case, Alex can get 2 + 7 = 9 stones. So we return greater 10.
prompt:
1 <= piles.length <= 100
1 <= piles[i] <= 10 ^ 4