-
Notifications
You must be signed in to change notification settings - Fork 0
/
15666.cpp
42 lines (38 loc) · 828 Bytes
/
15666.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
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int n, m;
int arr[9];
vector<int>numbers;
void recursive(int cnt, int lastN){
if(cnt == m){
for(int i = 0; i < m; i++){
cout << arr[i] << ' ';
}
cout << '\n';
return;
}
for(int i = lastN; i < numbers.size(); i++){
arr[cnt] = numbers[i];
recursive(cnt+1, i);
}
}
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;
bool possible = 1;
for(int j = i-1; j>= 0; j--){
if(numbers[j] == tmp)
possible = 0;
}
if(possible)numbers.push_back(tmp);
}
sort(numbers.begin(), numbers.end());
recursive(0, 0);
}