import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class boj15650 {
static int N, M;
static int[] foo;
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];
// visit = new boolean[N];
DFS(1, 0);
}
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 + 1, depth + 1);
}
}
public static void printArray(int[] array){
for(int i = 0; i < array.length ; i++){
System.out.print(array[i] + " ");
}
System.out.println();
}
}
Leave a comment