629. K Inverse Pairs Array Hard

@problem@discussion
#Dynamic Programming



1/**
2 * [629] K Inverse Pairs Array
3 *
4 * For an integer array nums, an inverse pair is a pair of integers [i, j] where 0 <= i < j < nums.length and nums[i] > nums[j].
5 * Given two integers n and k, return the number of different arrays consist of numbers from 1 to n such that there are exactly k inverse pairs. Since the answer can be huge, return it modulo 10^9 + 7.
6 *  
7 * Example 1:
8 * 
9 * Input: n = 3, k = 0
10 * Output: 1
11 * Explanation: Only the array [1,2,3] which consists of numbers from 1 to 3 has exactly 0 inverse pairs.
12 * 
13 * Example 2:
14 * 
15 * Input: n = 3, k = 1
16 * Output: 2
17 * Explanation: The array [1,3,2] and [2,1,3] have exactly 1 inverse pair.
18 * 
19 *  
20 * Constraints:
21 * 
22 * 	1 <= n <= 1000
23 * 	0 <= k <= 1000
24 * 
25 */
26pub struct Solution {}
27
28// problem: https://leetcode.com/problems/k-inverse-pairs-array/
29// discuss: https://leetcode.com/problems/k-inverse-pairs-array/discuss/?currentPage=1&orderBy=most_votes&query=
30
31// submission codes start here
32
33impl Solution {
34    pub fn k_inverse_pairs(n: i32, k: i32) -> i32 {
35        0
36    }
37}
38
39// submission codes end
40
41#[cfg(test)]
42mod tests {
43    use super::*;
44
45    #[test]
46    fn test_629() {
47    }
48}
49


Back
© 2025 bowen.ge All Rights Reserved.