/
BAEKJOON 15654
45 lines (40 loc) · 1.06 KB
/
BAEKJOON 15654
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
package BJ;
import java.io.*;
import java.util.*;
public class BJ15649N과M_5 {
static int[] in, out;
static boolean[] select;
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
in = new int[N];
select = new boolean[N];
out = new int[M];
st = new StringTokenizer(br.readLine());
for (int i = 0; i < N; i++) {
in[i] =Integer.parseInt(st.nextToken());
}
Arrays.sort(in);
comb(0);
bw.flush();
}
static void comb(int index) throws Exception{
if (index == out.length) {
for (int i = 0; i < out.length; i++) {
bw.write(out[i]+" ");
}
bw.newLine();
return;
}
for (int i = 0; i < in.length; i++) {
if(select[i]) continue;
out[index] = in[i];
select[i] = true;
comb(index + 1);
select[i] = false;
}
}
}