-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path526.cpp
More file actions
23 lines (22 loc) · 726 Bytes
/
Copy path526.cpp
File metadata and controls
23 lines (22 loc) · 726 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Solution {
public:
int countArrangement(int N) {
vector<int> tempList;
vector<vector<int>> result;
buildBeautiful(result, tempList, 1, N);
return result.size();
}
void buildBeautiful(vector<vector<int>> &result, vector<int> tempList, int start, int end){
if(start > end ){
result.push_back(tempList);
return;
}
for(int i=1; i<=end; i++){
if(((tempList.size()+1)%i) != 0 && (i%(tempList.size()+1)) != 0) continue;
else if(find(tempList.begin(), tempList.end(), i) != tempList.end()) continue;
tempList.push_back(i);
buildBeautiful(result, tempList, start+1, end);
tempList.pop_back();
}
}
};