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)/选择矩阵中单元格的最大得分 [select-cells-in-grid-with-maximum-score].html
2024-09-19 09:27:23 +08:00

52 lines
1.7 KiB
HTML
Raw 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>给你一个由正整数构成的二维矩阵 <code>grid</code></p>
<p>你需要从矩阵中选择<strong> 一个或多个 </strong>单元格,选中的单元格应满足以下条件:</p>
<ul>
<li>所选单元格中的任意两个单元格都不会处于矩阵的 <strong>同一行</strong></li>
<li>所选单元格的值 <strong>互不相同</strong></li>
</ul>
<p>你的得分为所选单元格值的<strong>总和</strong></p>
<p>返回你能获得的<strong> 最大 </strong>得分。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">grid = [[1,2,3],[4,3,2],[1,1,1]]</span></p>
<p><strong>输出:</strong> <span class="example-io">8</span></p>
<p><strong>解释:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/07/29/grid1drawio.png" /></p>
<p>选择上图中用彩色标记的单元格,对应的值分别为 1、3 和 4 。</p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">grid = [[8,7,6],[8,3,2]]</span></p>
<p><strong>输出:</strong> <span class="example-io">15</span></p>
<p><strong>解释:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/07/29/grid8_8drawio.png" style="width: 170px; height: 114px;" /></p>
<p>选择上图中用彩色标记的单元格,对应的值分别为 7 和 8 。</p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= grid.length, grid[i].length &lt;= 10</code></li>
<li><code>1 &lt;= grid[i][j] &lt;= 100</code></li>
</ul>