-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
39 lines (32 loc) Β· 1.01 KB
/
Main.java
File metadata and controls
39 lines (32 loc) Β· 1.01 KB
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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
static int[] arr;
static int n, m;
static StringBuilder sb = new StringBuilder();
public static void main(String[] args) throws IOException {
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[m];
dfs(1, 0);
System.out.println(sb);
}
public static void dfs(int idx, int depth) {
if(depth == m) {
for (int v : arr) {
sb.append(v).append(" ");
}
sb.append('\n');
return;
}
// idxλ₯Ό μ¦κ°μν€λ©΄μ idxλΆν° μ¬κ· νΈμΆ
for (int i = idx; i <= n; i++) {
arr[depth] = i;
dfs(i + 1, depth + 1);
}
}
}