526. Beautiful Arrangement Medium

@problem@discussion
#Array#Dynamic Programming#Backtracking#Bit Manipulation#Bitmask



1/**
2 * [526] Beautiful Arrangement
3 *
4 * Suppose you have n integers labeled 1 through n. A permutation of those n integers perm (1-indexed) is considered a beautiful arrangement if for every i (1 <= i <= n), either of the following is true:
5 * 
6 * 	perm[i] is divisible by i.
7 * 	i is divisible by perm[i].
8 * 
9 * Given an integer n, return the number of the beautiful arrangements that you can construct.
10 *  
11 * Example 1:
12 * 
13 * Input: n = 2
14 * Output: 2
15 * Explanation: 
16 * The first beautiful arrangement is [1,2]:
17 *     - perm[1] = 1 is divisible by i = 1
18 *     - perm[2] = 2 is divisible by i = 2
19 * The second beautiful arrangement is [2,1]:
20 *     - perm[1] = 2 is divisible by i = 1
21 *     - i = 2 is divisible by perm[2] = 1
22 * 
23 * Example 2:
24 * 
25 * Input: n = 1
26 * Output: 1
27 * 
28 *  
29 * Constraints:
30 * 
31 * 	1 <= n <= 15
32 * 
33 */
34pub struct Solution {}
35
36// problem: https://leetcode.com/problems/beautiful-arrangement/
37// discuss: https://leetcode.com/problems/beautiful-arrangement/discuss/?currentPage=1&orderBy=most_votes&query=
38
39// submission codes start here
40
41impl Solution {
42    pub fn count_arrangement(n: i32) -> i32 {
43        0
44    }
45}
46
47// submission codes end
48
49#[cfg(test)]
50mod tests {
51    use super::*;
52
53    #[test]
54    fn test_526() {
55    }
56}
57


Back
© 2025 bowen.ge All Rights Reserved.