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 个逆序对数组 [k-inverse-pairs-array].html
2023-12-09 18:53:53 +08:00

33 lines
1.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>逆序对的定义如下:对于数组 <code>nums</code> 的第 <code>i</code> 个和第 <code>j</code> 个元素,如果满足 <code>0 &lt;= i &lt; j &lt; nums.length</code>&nbsp;<code>nums[i] &gt; nums[j]</code>,则其为一个逆序对;否则不是。</p>
<p>给你两个整数&nbsp;<code>n</code>&nbsp;&nbsp;<code>k</code>,找出所有包含从&nbsp;<code>1</code>&nbsp;&nbsp;<code>n</code>&nbsp;的数字,且恰好拥有&nbsp;<code>k</code>&nbsp;<strong>逆序对</strong> 的不同的数组的个数。由于答案可能很大,只需要返回对 <code>10<sup>9</sup>&nbsp;+ 7</code> 取余的结果。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>n = 3, k = 0
<strong>输出:</strong>1
<strong>解释:</strong>
只有数组 [1,2,3] 包含了从1到3的整数并且正好拥有 0 个逆序对。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>n = 3, k = 1
<strong>输出:</strong>2
<strong>解释:</strong>
数组 [1,3,2] 和 [2,1,3] 都有 1 个逆序对。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= n &lt;= 1000</code></li>
<li><code>0 &lt;= k &lt;= 1000</code></li>
</ul>