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)/第 K 条最小指令 [kth-smallest-instructions].html
2022-03-29 12:43:11 +08:00

59 lines
2.7 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>Bob 站在单元格 <code>(0, 0)</code> ,想要前往目的地 <code>destination</code> <code>(row, column)</code> 。他只能向 <strong></strong> 或向 <strong></strong> 走。你可以为 Bob 提供导航 <strong>指令</strong> 来帮助他到达目的地 <code>destination</code></p>
<p><strong>指令</strong> 用字符串表示,其中每个字符:</p>
<ul>
<li><code>'H'</code> ,意味着水平向右移动</li>
<li><code>'V'</code> ,意味着竖直向下移动</li>
</ul>
<p>能够为 Bob 导航到目的地 <code>destination</code> 的指令可以有多种,例如,如果目的地 <code>destination</code><code>(2, 3)</code><code>"HHHVV"</code><code>"HVHVH"</code> 都是有效<strong> 指令</strong></p>
<ul>
</ul>
<p>然而Bob 很挑剔。因为他的幸运数字是 <code>k</code>,他想要遵循 <strong>按字典序排列后的第 <code>k</code> 条最小指令 </strong>的导航前往目的地 <code>destination</code><code>k</code>  的编号 <strong>从 1 开始</strong></p>
<p>给你一个整数数组 <code>destination</code> 和一个整数 <code>k</code> ,请你返回可以为<em> </em>Bob<em> </em>提供前往目的地 <code>destination</code> 导航的<strong> 按字典序排列后的第 <code>k</code> 条最小指令 </strong></p>
<p> </p>
<p><strong>示例 1</strong></p>
<p><img alt="" src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2020/11/01/ex1.png" style="width: 300px;" /></p>
<pre>
<strong>输入:</strong>destination = [2,3], k = 1
<strong>输出:</strong>"HHHVV"
<strong>解释:</strong>能前往 (2, 3) 的所有导航指令 <strong>按字典序排列后</strong> 如下所示:
["HHHVV", "HHVHV", "HHVVH", "HVHHV", "HVHVH", "HVVHH", "VHHHV", "VHHVH", "VHVHH", "VVHHH"].
</pre>
<p><strong>示例 2</strong></p>
<p><strong><img alt="" src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2020/11/01/ex2.png" style="width: 300px; height: 229px;" /></strong></p>
<pre>
<strong>输入:</strong>destination = [2,3], k = 2
<strong>输出:</strong>"HHVHV"
</pre>
<p><strong>示例 3</strong></p>
<p><strong><img alt="" src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2020/11/01/ex3.png" style="width: 300px; height: 229px;" /></strong></p>
<pre>
<strong>输入:</strong>destination = [2,3], k = 3
<strong>输出:</strong>"HHVVH"
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>destination.length == 2</code></li>
<li><code>1 <= row, column <= 15</code></li>
<li><code>1 <= k <= nCr(row + column, row)</code>,其中 <code>nCr(a, b)</code> 表示组合数,即从 <code>a</code> 个物品中选 <code>b</code> 个物品的不同方案数。</li>
</ul>