import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class boj15652 {
static int N, M;
static int[] foo;
static StringBuilder sb = new StringBuilder();
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());
foo = new int[M];
DFS(1, 0);
System.out.print(sb);
}
public static void DFS(int idx, int depth){
if (depth == M){
// 탐색 종료 조건 : 길이가 M printArray(foo);
return;
}
// 재귀 호출을 통한 DFS 구현
for(int i = idx; i <= N; i++){
foo[depth] = i; // depth 에 잇는 값 i로 바꿔줌
DFS(i, depth + 1);
}
}
public static void printArray(int[] array){
for(int i = 0; i < array.length ; i++){
sb.append(foo[i] + " ");
}
sb.append("\n");
}
}
Leave a comment