Skip to content

Commit f0d0a55

Browse files
authored
[BOJ] 15656 N과M 7 (S3)
1 parent 3dcc74a commit f0d0a55

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

정건우/3주차/260114.java

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//https://www.acmicpc.net/problem/15656
2+
import java.io.BufferedReader;
3+
import java.io.IOException;
4+
import java.io.InputStreamReader;
5+
import java.util.Arrays;
6+
import java.util.StringTokenizer;
7+
8+
public class BOJ_S3_15656_N과M7 {
9+
static int [] nums, picks;
10+
static int N, M;
11+
static StringBuilder sb;
12+
13+
public static void main(String[] args) throws IOException {
14+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
15+
StringTokenizer st = new StringTokenizer(br.readLine());
16+
17+
N = Integer.parseInt(st.nextToken());
18+
M = Integer.parseInt(st.nextToken());
19+
20+
nums = new int[N];
21+
picks = new int[M];
22+
sb = new StringBuilder();
23+
24+
st = new StringTokenizer(br.readLine());
25+
for (int i = 0; i < N; i++) {
26+
nums[i] = Integer.parseInt(st.nextToken());
27+
}
28+
29+
Arrays.sort(nums);
30+
31+
perm(0);
32+
33+
System.out.println(sb.toString());
34+
35+
}
36+
37+
private static void perm(int depth) {
38+
if (depth == M) {
39+
for (int num : picks) {
40+
sb.append(num).append(" ");
41+
}
42+
43+
sb.setLength(sb.length()-1);
44+
sb.append("\n");
45+
46+
return;
47+
}
48+
49+
for (int i = 0; i < N; i++) {
50+
picks[depth] = nums[i];
51+
perm(depth + 1);
52+
}
53+
54+
}
55+
}

0 commit comments

Comments
 (0)