[알고리즘] 백준 - 15650 ( N과 M (2) ) / 자바

배고픈메꾸리·2021년 4월 1일
0

알고리즘

목록 보기
70/128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

class Main {
	static int N, M;
	static int[] arr;
	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.print(sb);
	}

	public static void dfs(int at, int depth) {
		if (depth == M) {
			for (int value : arr) {
				sb.append(value).append(" ");
			}
			sb.append("\n");
			return;
		}

		for (int i = at; i <= N; i++) {
			arr[depth] = i;
			dfs(i + 1, depth + 1);
		}

	}

}```

![](https://velog.velcdn.com/images%2Fcheal3%2Fpost%2Ff7354ff3-a530-471d-a4ab-b93c9daa82df%2Fimage.png)
profile
FE 개발자가 되자

0개의 댓글