526 Beautiful Arrangement
Suppose you have N integers from 1 to N. We define a beautiful arrangement as an array that is constructed by these N numbers successfully if one of the following is true for the ith position (1 ≤ i ≤ N) in this array:
- The number at the ith position is divisible by i.
- i is divisible by the number at the ith position.
Now given N, how many beautiful arrangements can you construct?
Example 1:
|
|
Note:
- N is a positive integer and will not exceed 15.
思路
在这一题中,我们利用回溯算法来解决问题。
回溯算法和穷举的方法有点类似,利用递归的方式,指定限制条件从而可以在问题集当中递归地访问,从而得出问题的可行解。
|
|