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)/石子游戏 VII [stone-game-vii].html
2022-03-29 12:43:11 +08:00

40 lines
1.9 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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>石子游戏中,爱丽丝和鲍勃轮流进行自己的回合,<strong>爱丽丝先开始</strong></p>
<p><code>n</code> 块石子排成一排。每个玩家的回合中,可以从行中 <strong>移除</strong> 最左边的石头或最右边的石头,并获得与该行中剩余石头值之 <strong></strong> 相等的得分。当没有石头可移除时,得分较高者获胜。</p>
<p>鲍勃发现他总是输掉游戏(可怜的鲍勃,他总是输),所以他决定尽力 <strong>减小得分的差值</strong> 。爱丽丝的目标是最大限度地 <strong>扩大得分的差值</strong></p>
<p>给你一个整数数组 <code>stones</code> ,其中 <code>stones[i]</code> 表示 <strong>从左边开始</strong> 的第 <code>i</code> 个石头的值,如果爱丽丝和鲍勃都 <strong>发挥出最佳水平</strong> ,请返回他们 <strong>得分的差值</strong></p>
<p> </p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>stones = [5,3,1,4,2]
<strong>输出:</strong>6
<strong>解释:</strong>
- 爱丽丝移除 2 ,得分 5 + 3 + 1 + 4 = 13 。游戏情况:爱丽丝 = 13 ,鲍勃 = 0 ,石子 = [5,3,1,4] 。
- 鲍勃移除 5 ,得分 3 + 1 + 4 = 8 。游戏情况:爱丽丝 = 13 ,鲍勃 = 8 ,石子 = [3,1,4] 。
- 爱丽丝移除 3 ,得分 1 + 4 = 5 。游戏情况:爱丽丝 = 18 ,鲍勃 = 8 ,石子 = [1,4] 。
- 鲍勃移除 1 ,得分 4 。游戏情况:爱丽丝 = 18 ,鲍勃 = 12 ,石子 = [4] 。
- 爱丽丝移除 4 ,得分 0 。游戏情况:爱丽丝 = 18 ,鲍勃 = 12 ,石子 = [] 。
得分的差值 18 - 12 = 6 。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>stones = [7,90,5,1,100,10,10,2]
<strong>输出:</strong>122</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>n == stones.length</code></li>
<li><code>2 <= n <= 1000</code></li>
<li><code>1 <= stones[i] <= 1000</code></li>
</ul>