1621. Number of Sets of K Non-Overlapping Line Segments Medium

@problem@discussion
#Math#Dynamic Programming



1/**
2 * [1621] Number of Sets of K Non-Overlapping Line Segments
3 *
4 * Given n points on a 1-D plane, where the i^th point (from 0 to n-1) is at x = i, find the number of ways we can draw exactly k non-overlapping line segments such that each segment covers two or more points. The endpoints of each segment must have integral coordinates. The k line segments do not have to cover all n points, and they are allowed to share endpoints.
5 * Return the number of ways we can draw k non-overlapping line segments. Since this number can be huge, return it modulo 10^9 + 7.
6 *  
7 * Example 1:
8 * <img alt="" src="https://assets.leetcode.com/uploads/2020/09/07/ex1.png" style="width: 179px; height: 222px;" />
9 * Input: n = 4, k = 2
10 * Output: 5
11 * Explanation: The two line segments are shown in red and blue.
12 * The image above shows the 5 different ways {(0,2),(2,3)}, {(0,1),(1,3)}, {(0,1),(2,3)}, {(1,2),(2,3)}, {(0,1),(1,2)}.
13 * 
14 * Example 2:
15 * 
16 * Input: n = 3, k = 1
17 * Output: 3
18 * Explanation: The 3 ways are {(0,1)}, {(0,2)}, {(1,2)}.
19 * 
20 * Example 3:
21 * 
22 * Input: n = 30, k = 7
23 * Output: 796297179
24 * Explanation: The total number of possible ways to draw 7 line segments is 3796297200. Taking this number modulo 10^9 + 7 gives us 796297179.
25 * 
26 *  
27 * Constraints:
28 * 
29 * 	2 <= n <= 1000
30 * 	1 <= k <= n-1
31 * 
32 */
33pub struct Solution {}
34
35// problem: https://leetcode.com/problems/number-of-sets-of-k-non-overlapping-line-segments/
36// discuss: https://leetcode.com/problems/number-of-sets-of-k-non-overlapping-line-segments/discuss/?currentPage=1&orderBy=most_votes&query=
37
38// submission codes start here
39
40impl Solution {
41    pub fn number_of_sets(n: i32, k: i32) -> i32 {
42        0
43    }
44}
45
46// submission codes end
47
48#[cfg(test)]
49mod tests {
50    use super::*;
51
52    #[test]
53    fn test_1621() {
54    }
55}
56


Back
© 2025 bowen.ge All Rights Reserved.