-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path15654.cpp
More file actions
47 lines (39 loc) · 734 Bytes
/
15654.cpp
File metadata and controls
47 lines (39 loc) · 734 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 <algorithm>
using namespace std;
int N, M;
vector<int> n;
bool selected[8];
vector<int> v;
void print() {
for (int i = 0; i < v.size(); i++) {
cout << v[i] << " ";
}
cout << "\n";
}
void DFS(int cnt) {
if (cnt == M) {
print();
return;
}
for (int i = 0; i < N; i++) {
if (selected[i]) continue;
selected[i] = true;
v.push_back(n[i]);
DFS(cnt + 1);
v.pop_back();
selected[i] = false;
}
}
int main() {
cin >> N >> M;
for (int i = 0; i < N; i++) {
int a;
cin >> a;
n.push_back(a);
}
sort(n.begin(), n.end());
DFS(0);
return 0;
}