-
Notifications
You must be signed in to change notification settings - Fork 0
/
15654.cpp
53 lines (45 loc) · 788 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
47
48
49
50
51
52
53
#include <iostream>
#include <algorithm>
using namespace std;
int arr[8] = {0};
int arr2[8];
int check_num (int N, int num)
{
for (int i = 0; i < num; i++)
{
if (arr[i] == N)
return 0;
}
return 1;
}
void pick_num(int N, int M, int num)
{
if (M == num)
{
for (int i = 0; i < M; i++)
{
cout << arr[i] << " ";
}
cout << '\n';
return;
}
for (int i = 0; i < N; i++)
{
if(check_num(arr2[i], num))
{
arr[num] = arr2[i];
pick_num(N, M, num + 1);
}
}
}
int main(void)
{
int M, N;
cin >> N >> M;
for(int i = 0; i < N; i++)
{
cin >> arr2[i];
}
sort(arr2, arr2 + N);
pick_num(N, M, 0);
}