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)/扣分后的最大得分 [maximum-number-of-points-with-cost].html
2022-03-29 12:43:11 +08:00

53 lines
2.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>m x n</code> 的整数矩阵 <code>points</code> (下标从 <strong>0</strong> 开始)。一开始你的得分为 <code>0</code> ,你想最大化从矩阵中得到的分数。</p>
<p>你的得分方式为:<strong>每一行</strong> 中选取一个格子,选中坐标为 <code>(r, c)</code> 的格子会给你的总得分 <strong>增加</strong> <code>points[r][c]</code> 。</p>
<p>然而,相邻行之间被选中的格子如果隔得太远,你会失去一些得分。对于相邻行 <code>r</code> 和 <code>r + 1</code> (其中 <code>0 <= r < m - 1</code>),选中坐标为 <code>(r, c<sub>1</sub>)</code> 和 <code>(r + 1, c<sub>2</sub>)</code> 的格子,你的总得分 <b>减少</b> <code>abs(c<sub>1</sub> - c<sub>2</sub>)</code> 。</p>
<p>请你返回你能得到的 <strong>最大</strong> 得分。</p>
<p><code>abs(x)</code> 定义为:</p>
<ul>
<li>如果 <code>x >= 0</code> ,那么值为 <code>x</code> 。</li>
<li>如果 <code>x < 0</code> ,那么值为 <code>-x</code> 。</li>
</ul>
<p> </p>
<p><strong>示例 1</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/07/12/screenshot-2021-07-12-at-13-40-26-diagram-drawio-diagrams-net.png" style="width: 300px; height: 300px;" />
<pre>
<b>输入:</b>points = [[1,2,3],[1,5,1],[3,1,1]]
<b>输出:</b>9
<strong>解释:</strong>
蓝色格子是最优方案选中的格子,坐标分别为 (0, 2)(1, 1) 和 (2, 0) 。
你的总得分增加 3 + 5 + 3 = 11 。
但是你的总得分需要扣除 abs(2 - 1) + abs(1 - 0) = 2 。
你的最终得分为 11 - 2 = 9 。
</pre>
<p><strong>示例 2</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/07/12/screenshot-2021-07-12-at-13-42-14-diagram-drawio-diagrams-net.png" style="width: 200px; height: 299px;" />
<pre>
<b>输入:</b>points = [[1,5],[2,3],[4,2]]
<b>输出:</b>11
<strong>解释:</strong>
蓝色格子是最优方案选中的格子,坐标分别为 (0, 1)(1, 1) 和 (2, 0) 。
你的总得分增加 5 + 3 + 4 = 12 。
但是你的总得分需要扣除 abs(1 - 1) + abs(1 - 0) = 1 。
你的最终得分为 12 - 1 = 11 。
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>m == points.length</code></li>
<li><code>n == points[r].length</code></li>
<li><code>1 <= m, n <= 10<sup>5</sup></code></li>
<li><code>1 <= m * n <= 10<sup>5</sup></code></li>
<li><code>0 <= points[r][c] <= 10<sup>5</sup></code></li>
</ul>