-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday43.cpp
More file actions
47 lines (36 loc) · 976 Bytes
/
day43.cpp
File metadata and controls
47 lines (36 loc) · 976 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
void generatePermutations(vector<int>& heights, int k, set<vector<int>>& uniqueSkylines, int depth = 0) {
if (depth == k) {
uniqueSkylines.insert(heights);
return;
}
for (int i = depth; i < heights.size(); ++i) {
swap(heights[depth], heights[i]);
generatePermutations(heights, k, uniqueSkylines, depth + 1);
swap(heights[depth], heights[i]);
}
if (depth < heights.size()) {
uniqueSkylines.insert(heights);
}
}
int main() {
int t;
cin >> t;
while (t--) {
int n, k;
cin >> n;
vector<int> heights(n);
for (int i = 0; i < n; ++i) {
cin >> heights[i];
}
cin >> k;
set<vector<int>> uniqueSkylines;
generatePermutations(heights, k, uniqueSkylines);
cout << uniqueSkylines.size() << endl;
}
return 0;
}