/
BAEKJOON 15656
37 lines (34 loc) · 954 Bytes
/
BAEKJOON 15656
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
import java.io.*;
import java.util.*;
public class Main {
static int[] in, out;
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];
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,0);
bw.flush();
}
static void comb(int start,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 = start; i < in.length; i++) {
out[index] = in[i];
comb(start,index + 1);
}
}
}