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)/恰有 K 根木棍可以看到的排列数目 [number-of-ways-to-rearrange-sticks-with-k-sticks-visible].html
2022-03-29 12:43:11 +08:00

42 lines
2.1 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>n</code> 根长度互不相同的木棍,长度为从 <code>1</code><code>n</code> 的整数。请你将这些木棍排成一排,并满足从左侧 <strong>可以看到</strong> <strong>恰好</strong> <code>k</code> 根木棍。从左侧 <strong>可以看到</strong> 木棍的前提是这个木棍的 <strong>左侧</strong> 不存在比它 <strong>更长的</strong> 木棍。</p>
<ul>
<li>例如,如果木棍排列为 <code>[<em><strong>1</strong></em>,<em><strong>3</strong></em>,2,<em><strong>5</strong></em>,4]</code> ,那么从左侧可以看到的就是长度分别为 <code>1</code><code>3</code><code>5</code> 的木棍。</li>
</ul>
<p>给你 <code>n</code><code>k</code> ,返回符合题目要求的排列 <strong>数目</strong> 。由于答案可能很大,请返回对 <code>10<sup>9</sup> + 7</code> <strong>取余 </strong>的结果。</p>
<p> </p>
<p><strong>示例 1</strong></p>
<pre><strong>输入:</strong>n = 3, k = 2
<strong>输出:</strong>3
<strong>解释:</strong>[<strong><em>1</em></strong>,<strong><em>3</em></strong>,2], [<em><strong>2</strong></em>,<em><strong>3</strong></em>,1] 和 [<em><strong>2</strong></em>,1,<em><strong>3</strong></em>] 是仅有的能满足恰好 2 根木棍可以看到的排列。
可以看到的木棍已经用粗体+斜体标识。
</pre>
<p><strong>示例 2</strong></p>
<pre><strong>输入:</strong>n = 5, k = 5
<strong>输出:</strong>1
<strong>解释:</strong>[<em><strong>1</strong></em>,<em><strong>2</strong></em>,<em><strong>3</strong></em>,<em><strong>4</strong></em>,<em><strong>5</strong></em>] 是唯一一种能满足全部 5 根木棍可以看到的排列。
可以看到的木棍已经用粗体+斜体标识。
</pre>
<p><strong>示例 3</strong></p>
<pre><strong>输入:</strong>n = 20, k = 11
<strong>输出:</strong>647427950
<strong>解释:</strong>总共有 647427950 (mod 10<sup>9 </sup>+ 7) 种能满足恰好有 11 根木棍可以看到的排列。
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= n &lt;= 1000</code></li>
<li><code>1 &lt;= k &lt;= n</code></li>
</ul>