백준 15650번(Java)

박은지·2025년 6월 25일
0

백준

목록 보기
89/89
post-thumbnail

import java.io.*;
import java.util.*;

public class Main {

	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());
		
		N = Integer.parseInt(st.nextToken());
		M = Integer.parseInt(st.nextToken());
		
		arr = new int[M];
		
		dfs(1,0);
		System.out.println(sb);
	}
	
	public static void dfs(int at, int depth) {
		if(depth == M) {
			for(int val:arr) {
				sb.append(val).append(' ');
			}
			sb.append('\n');
			return;
		}
		
		for(int i=at; i<=N; i++) {
			arr[depth] = i;
			dfs(i+1, depth+1);
		}
	}
}
profile
백엔드 개발자가 되고싶은 eunzi😊

0개의 댓글