1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-09-12 02:41:42 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
Files
leetcode-problemset/leetcode-cn/problem (English)/带传送的最小路径成本(English) [minimum-cost-path-with-teleportations].html
2025-09-02 22:45:58 +08:00

113 lines
4.2 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>You are given a <code>m x n</code> 2D integer array <code>grid</code> and an integer <code>k</code>. You start at the top-left cell <code>(0, 0)</code> and your goal is to reach the bottomright cell <code>(m - 1, n - 1)</code>.</p>
<p>There are two types of moves available:</p>
<ul>
<li>
<p><strong>Normal move</strong>: You can move right or down from your current cell <code>(i, j)</code>, i.e. you can move to <code>(i, j + 1)</code> (right) or <code>(i + 1, j)</code> (down). The cost is the value of the destination cell.</p>
</li>
<li>
<p><strong>Teleportation</strong>: You can teleport from any cell <code>(i, j)</code>, to any cell <code>(x, y)</code> such that <code>grid[x][y] &lt;= grid[i][j]</code>; the cost of this move is 0. You may teleport at most <code>k</code> times.</p>
</li>
</ul>
<p>Return the <strong>minimum</strong> total cost to reach cell <code>(m - 1, n - 1)</code> from <code>(0, 0)</code>.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">grid = [[1,3,3],[2,5,4],[4,3,5]], k = 2</span></p>
<p><strong>Output:</strong> <span class="example-io">7</span></p>
<p><strong>Explanation:</strong></p>
<p>Initially we are at (0, 0) and cost is 0.</p>
<table style="border: 1px solid black;">
<tbody>
<tr>
<th style="border: 1px solid black;">Current Position</th>
<th style="border: 1px solid black;">Move</th>
<th style="border: 1px solid black;">New Position</th>
<th style="border: 1px solid black;">Total Cost</th>
</tr>
<tr>
<td style="border: 1px solid black;"><code>(0, 0)</code></td>
<td style="border: 1px solid black;">Move Down</td>
<td style="border: 1px solid black;"><code>(1, 0)</code></td>
<td style="border: 1px solid black;"><code>0 + 2 = 2</code></td>
</tr>
<tr>
<td style="border: 1px solid black;"><code>(1, 0)</code></td>
<td style="border: 1px solid black;">Move Right</td>
<td style="border: 1px solid black;"><code>(1, 1)</code></td>
<td style="border: 1px solid black;"><code>2 + 5 = 7</code></td>
</tr>
<tr>
<td style="border: 1px solid black;"><code>(1, 1)</code></td>
<td style="border: 1px solid black;">Teleport to <code>(2, 2)</code></td>
<td style="border: 1px solid black;"><code>(2, 2)</code></td>
<td style="border: 1px solid black;"><code>7 + 0 = 7</code></td>
</tr>
</tbody>
</table>
<p>The minimum cost to reach bottom-right cell is 7.</p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">grid = [[1,2],[2,3],[3,4]], k = 1</span></p>
<p><strong>Output:</strong> <span class="example-io">9</span></p>
<p><strong>Explanation: </strong></p>
<p>Initially we are at (0, 0) and cost is 0.</p>
<table style="border: 1px solid black;">
<tbody>
<tr>
<th style="border: 1px solid black;">Current Position</th>
<th style="border: 1px solid black;">Move</th>
<th style="border: 1px solid black;">New Position</th>
<th style="border: 1px solid black;">Total Cost</th>
</tr>
<tr>
<td style="border: 1px solid black;"><code>(0, 0)</code></td>
<td style="border: 1px solid black;">Move Down</td>
<td style="border: 1px solid black;"><code>(1, 0)</code></td>
<td style="border: 1px solid black;"><code>0 + 2 = 2</code></td>
</tr>
<tr>
<td style="border: 1px solid black;"><code>(1, 0)</code></td>
<td style="border: 1px solid black;">Move Right</td>
<td style="border: 1px solid black;"><code>(1, 1)</code></td>
<td style="border: 1px solid black;"><code>2 + 3 = 5</code></td>
</tr>
<tr>
<td style="border: 1px solid black;"><code>(1, 1)</code></td>
<td style="border: 1px solid black;">Move Down</td>
<td style="border: 1px solid black;"><code>(2, 1)</code></td>
<td style="border: 1px solid black;"><code>5 + 4 = 9</code></td>
</tr>
</tbody>
</table>
<p>The minimum cost to reach bottom-right cell is 9.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>2 &lt;= m, n &lt;= 80</code></li>
<li><code>m == grid.length</code></li>
<li><code>n == grid[i].length</code></li>
<li><code>0 &lt;= grid[i][j] &lt;= 10<sup>4</sup></code></li>
<li><code>0 &lt;= k &lt;= 10</code></li>
</ul>