Skip to content

Commit 0386125

Browse files
committed
issue #41 15650 N과 M (2)
1 parent 28dc189 commit 0386125

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

src/backjoon/_15650.java

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package backjoon;
2+
// https://www.acmicpc.net/problem/15650
3+
// N과 M (2)
4+
import java.io.BufferedReader;
5+
import java.io.IOException;
6+
import java.io.InputStreamReader;
7+
import java.util.StringTokenizer;
8+
9+
public class _15650 {
10+
public static int[] arr;
11+
public static int N, M;
12+
public static StringBuilder sb = new StringBuilder();
13+
14+
public static void main(String[] args) throws IOException {
15+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
16+
StringTokenizer st = new StringTokenizer(br.readLine());
17+
// memory 11520 runtime 80
18+
N = Integer.parseInt(st.nextToken());
19+
M = Integer.parseInt(st.nextToken());
20+
21+
arr = new int[M];
22+
dfs(1,0);
23+
System.out.println(sb);
24+
}
25+
26+
static void dfs(int current, int depth){
27+
28+
if(depth == M){
29+
for(int v : arr){
30+
sb.append(v).append(" ");
31+
}
32+
sb.append("\n");
33+
return;
34+
}
35+
36+
for(int i=current; i<=N; i++){
37+
arr[depth] = i;
38+
dfs(i+1, depth+1);
39+
}
40+
}
41+
42+
}
43+
/*
44+
input
45+
4 2
46+
47+
output
48+
1 2
49+
1 3
50+
1 4
51+
2 3
52+
2 4
53+
3 4
54+
*/

0 commit comments

Comments
 (0)