-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path15654.cpp
More file actions
53 lines (48 loc) · 879 Bytes
/
15654.cpp
File metadata and controls
53 lines (48 loc) · 879 Bytes
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
// 15654. N과 M (5)
// 2020.12.31
// N과 M
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int n, m;
bool visit[10];
int arr[10];
vector<int> v;
void go(int count)
{
// m개만큼 다 뽑았을 때
if (count == m)
{
for (int i = 0; i < m; i++)
{
// cout 사용시 시간초과
printf("%d ", v[arr[i]]);
}
printf("\n");
}
for (int i = 0; i < n; i++)
{
// 중복을 피하기 위해 visit배열 체크
if (!visit[i])
{
visit[i] = true;
arr[count] = i;
go(count + 1);
visit[i] = false;
}
}
}
int main()
{
cin >> n >> m;
for (int i = 0; i < n; i++)
{
int k;
cin >> k;
v.push_back(k);
}
sort(v.begin(), v.end());
go(0);
return 0;
}