-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ15664_NM(10).cpp
More file actions
60 lines (53 loc) · 1.08 KB
/
BOJ15664_NM(10).cpp
File metadata and controls
60 lines (53 loc) · 1.08 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
//
// main.cpp
// BOJ15664_NM(10)
//
// Created by 신지식 on 2018. 9. 28..
// Copyright © 2018년 Shin Ji Sik. All rights reserved.
//
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
int n, m;
vector<int> v, a;
int check[9];
set<vector<int>> s;
bool ascending(){
for(int i = 0; i < m-1; i++)
if(a[i] > a[i+1])
return false;
return true;
}
void dfs(int cnt){
if(cnt == m){
auto iter = s.find(a);
s.insert(a);
if(iter == s.end() && ascending()){
for(int i = 0; i < m; i++)
printf("%d ", a[i]);
printf("\n");
}
return;
}
for(int i = 0; i < n; i++){
if(check[i] == false){
check[i] = true;
a.push_back(v[i]);
dfs(cnt + 1);
check[i] = false;
a.pop_back();
}
}
}
int main(){
cin >> n >> m;
for(int i = 0; i < n; i++){
int num;
cin >> num;
v.push_back(num);
}
sort(v.begin(), v.end());
dfs(0);
}