Notice
Recent Posts
Recent Comments
Link
변수의 기록
(코테) 백준_1094_모든수열 백트레킹 본문
public class Backjun_10974 {
static int n;
static int[] list;
static int[] result;
static StringBuilder sb = new StringBuilder();
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
n = Integer.parseInt(br.readLine());
list = new int[n + 1];
result = new int[n];
for (int i = 1; i <= n; i++) list[i] = 1;
dfs(0);
System.out.print(sb); // 여기서 단 한 번 출력
}
public static void dfs(int index) {
if (index == n) {
for (int i = 0; i < n; i++) {
sb.append(result[i]).append(" ");
}
sb.append("\n");
return;
}
for (int j = 1; j <= n; j++) {
if (list[j] > 0) {
list[j]--;
result[index] = j;
dfs(index + 1);
list[j]++;
}
}
}
}