📍 문제 설명

💡 접근
N개 중에 M개 뽑는 조합의 문제이다.
https://inseongdev.tistory.com/146?category=906158
조합 구하기(DFS)
보호되어 있는 글입니다. 내용을 보시려면 비밀번호를 입력하세요.
inseongdev.tistory.com
👩💻 코드
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
//조합 뽑아낼 배열
static int[] combi;
static int n, m;
public static StringBuilder sb = new StringBuilder();
private void dfs(int L, int s) {
if(L == m) {
for(int x : combi) sb.append(x).append(' ');
sb.append("\n");
}
else {
for(int i = s; i <= n; i++) {
combi[L] = i;
dfs(L+1, i+1);
}
}
}
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());
combi = new int[m];
//n개 중에 m개를 뽑는 경우의 수를 구해야한다.
Main T = new Main();
T.dfs(0, 1);
System.out.println(sb);
}
}