-
Notifications
You must be signed in to change notification settings - Fork 0
/
15654.cpp
46 lines (45 loc) · 844 Bytes
/
15654.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
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
int N, M;
vector<int> V;
bool check[9];
void go(vector<int> &input)
{
if (V.size() == M)
{
for (vector<int>::iterator it = V.begin(); it != V.end(); it++)
{
printf("%d ", input[*it]);
}
puts("");
return;
}
for (int i = 0; i < N; i++)
{
if (check[i])
continue;
V.push_back(i);
check[i] = true;
go(input);
V.pop_back();
check[i] = false;
}
}
int main(void)
{
cin >> N >> M;
vector<int> input;
int temp;
for (int i = 0; i < N; i++)
{
cin >> temp;
input.push_back(temp);
}
sort(input.begin(), input.end());
go(input);
return 0;
}