https://www.acmicpc.net/problem/15652
import java.io.*;
import java.util.*;
public class Main {
static int n, m;
static int[] arr;
static StringBuilder result = 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+1];
recur(1);
System.out.println(result);
}
public static void recur(int depth) {
if (depth > m) {
for (int j=1; j<=m; j++) {
result.append(arr[j]).append(" ");
}
result.append("\n");
return;
}
for (int i=1; i<=n; i++) {
if (arr[depth-1] > i) continue;
arr[depth] = i;
recur(depth + 1);
}
}
}
'Algorithm Solving > Java' 카테고리의 다른 글
[BOJ] 백준 2559번 : 수열 - Java (0) | 2024.09.09 |
---|---|
[BOJ] 백준 14503번 : 로봇 청소기 - Java (0) | 2024.09.09 |
[BOJ] 백준 15651번 : N과 M (3) - Java (0) | 2024.09.09 |
[BOJ] 백준 15650번 : N과 M (2) - Java (0) | 2024.09.09 |
[BOJ] 백준 15649번 : N과 M (1) - Java (0) | 2024.09.09 |