1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/石子游戏 II [stone-game-ii].html
2022-03-29 12:43:11 +08:00

36 lines
1.5 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>爱丽丝和鲍勃继续他们的石子游戏。许多堆石子&nbsp;<strong>排成一行</strong>,每堆都有正整数颗石子&nbsp;<code>piles[i]</code>。游戏以谁手中的石子最多来决出胜负。</p>
<p>爱丽丝和鲍勃轮流进行,爱丽丝先开始。最初,<code>M = 1</code></p>
<p>在每个玩家的回合中,该玩家可以拿走剩下的&nbsp;<strong></strong>&nbsp;<code>X</code>&nbsp;堆的所有石子,其中&nbsp;<code>1 &lt;= X &lt;= 2M</code>。然后,令&nbsp;<code>M = max(M, X)</code></p>
<p>游戏一直持续到所有石子都被拿走。</p>
<p>假设爱丽丝和鲍勃都发挥出最佳水平,返回爱丽丝可以得到的最大数量的石头。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>piles = [2,7,9,4,4]
<strong>输出:</strong>10
<strong>解释:</strong>如果一开始Alice取了一堆Bob取了两堆然后Alice再取两堆。爱丽丝可以得到2 + 4 + 4 = 10堆。如果Alice一开始拿走了两堆那么Bob可以拿走剩下的三堆。在这种情况下Alice得到2 + 7 = 9堆。返回10因为它更大。
</pre>
<p><strong>示例 2:</strong></p>
<pre>
<strong>输入:</strong>piles = [1,2,3,4,5,100]
<strong>输出:</strong>104
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= piles.length &lt;= 100</code></li>
<li><meta charset="UTF-8" /><code>1 &lt;= piles[i]&nbsp;&lt;= 10<sup>4</sup></code></li>
</ul>