1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/N 次操作后的最大分数和 [maximize-score-after-n-operations].html
2022-03-29 12:43:11 +08:00

50 lines
1.4 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>给你 <code>nums</code> ,它是一个大小为 <code>2 * n</code> 的正整数数组。你必须对这个数组执行 <code>n</code> 次操作。</p>
<p>在第 <code>i</code> 次操作时(操作编号从 <strong>1</strong> 开始),你需要:</p>
<ul>
<li>选择两个元素 <code>x</code> 和 <code>y</code> 。</li>
<li>获得分数 <code>i * gcd(x, y)</code> 。</li>
<li>将 <code>x</code> 和 <code>y</code> 从 <code>nums</code> 中删除。</li>
</ul>
<p>请你返回 <code>n</code> 次操作后你能获得的分数和最大为多少。</p>
<p>函数 <code>gcd(x, y)</code> 是 <code>x</code> 和 <code>y</code> 的最大公约数。</p>
<p> </p>
<p><strong>示例 1</strong></p>
<pre><b>输入:</b>nums = [1,2]
<b>输出:</b>1
<b>解释:</b>最优操作是:
(1 * gcd(1, 2)) = 1
</pre>
<p><strong>示例 2</strong></p>
<pre><b>输入:</b>nums = [3,4,6,8]
<b>输出:</b>11
<b>解释:</b>最优操作是:
(1 * gcd(3, 6)) + (2 * gcd(4, 8)) = 3 + 8 = 11
</pre>
<p><strong>示例 3</strong></p>
<pre><b>输入:</b>nums = [1,2,3,4,5,6]
<b>输出:</b>14
<b>解释:</b>最优操作是:
(1 * gcd(1, 5)) + (2 * gcd(2, 4)) + (3 * gcd(3, 6)) = 1 + 4 + 9 = 14
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= n &lt;= 7</code></li>
<li><code>nums.length == 2 * n</code></li>
<li><code>1 &lt;= nums[i] &lt;= 10<sup>6</sup></code></li>
</ul>