728x90
https://www.acmicpc.net/problem/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
46
47
48
49
50
51
52
53
54
55
|
import java.util.*;
import java.io.*;
public class Main{
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
static int n, m;
static int[] arr;
static int[] result;
static int[] check;
static StringBuilder sb = new StringBuilder();
static void getResult(int x) {
if(x >= m) {
for(int i=0; i<m; i++) {
sb.append(result[i] + " ");
}
sb.append("\n");
} else {
for(int i=0; i<n; i++) {
if(check[i] == 0) {
check[i] = 1;
result[x] = arr[i];
getResult(x+1);
check[i] = 0;
}
}
}
}
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
n = Integer.parseInt(st.nextToken());
m = Integer.parseInt(st.nextToken());
arr = new int[n];
result = new int[m];
check = new int[n];
st = new StringTokenizer(br.readLine());
for(int i=0; i<n; i++) {
arr[i] = Integer.parseInt(st.nextToken());
}
Arrays.sort(arr);
getResult(0);
bw.write(sb.toString());
br.close();
bw.flush();
bw.close();
}
}
|
cs |
반응형