-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path15663.cpp
54 lines (49 loc) · 1016 Bytes
/
15663.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
41
42
43
44
45
46
47
48
49
50
51
52
53
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
using namespace std;
int n, m;
vector<int>v;
vector<int>arr = {0, 0, 0, 0, 0, 0, 0, 0, 0};
int lastArr[9] = {0, };
bool used[9] = {0, };
set<vector<int>>s;
void recursive(int cnt){
if(cnt == m) {
if(s.count(arr))return;
else s.insert(arr);
for(int i = 0; i < m; i++)
{
cout << arr[i] << ' ';
}
cout << '\n';
return;
}
for(int i = 0; i < v.size(); i++){
if(used[i] == 0){
used[i] = 1;
arr[cnt] = v[i];
recursive(cnt+1);
used[i] = 0;
}
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
int tmp;
for(int i = 0 ; i < n; i++){
cin >> tmp;
int count = 0;
for(int i = 0; i < v.size(); i++){
if(v[i] == tmp)
count++;
}
if(count < m) v.push_back(tmp);
}
sort(v.begin(), v.end());
recursive(0);
}