forked from tony9402/baekjoon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
40 lines (34 loc) · 759 Bytes
/
main.cpp
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
// Authored by : tony9402
// Co-authored by : -
// Link : http://boj.kr/07e0a7b8b518418d86ac107dcdf56a7e
#include<bits/stdc++.h>
using namespace std;
int arr[10], choose[10], N, M;
bool used[10];
void dfs(int cnt) {
if(cnt == M) {
for(int i=0;i<M;i++) {
cout << arr[choose[i]] << ' ';
}
cout << '\n';
return;
}
int pre = -1;
for(int i=0;i<N;i++) {
if(used[i] || pre == arr[i]) continue;
pre = arr[i];
used[i] = true;
choose[cnt] = i;
dfs(cnt + 1);
used[i] = false;
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N >> M;
for(int i=0;i<N;i++) cin >> arr[i];
sort(arr, arr + N);
dfs(0);
return 0;
}