-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy path_15652.java
More file actions
56 lines (50 loc) · 1.02 KB
/
_15652.java
File metadata and controls
56 lines (50 loc) · 1.02 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package backjoon;
// https://www.acmicpc.net/problem/15652
// N과 M (4)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class _15652 {
public static int[] arr;
public static int N, M;
public 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());
// memory 13464 runtime 92
N = Integer.parseInt(st.nextToken());
M = Integer.parseInt(st.nextToken());
arr = new int[M];
dfs(1,0);
System.out.println(sb);
}
static void dfs(int current, int depth){
if(depth == M){
for(int v : arr){
sb.append(v).append(" ");
}
sb.append("\n");
return;
}
for(int i=current; i<=N; i++){
arr[depth] = i;
dfs(i, depth+1);
}
}
}
/*
input
4 2
output
1 1
1 2
1 3
1 4
2 2
2 3
2 4
3 3
3 4
4 4
*/