문제링크
https://www.acmicpc.net/problem/10974
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main_10974 {
private static int N;
private static int arr[];
private static boolean isSelected[];
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
N = Integer.parseInt(br.readLine());
arr = new int[N];
isSelected = new boolean[N];
perm(0);
}
private static void perm(int cnt) {
if(cnt == N) {
for(int i=0;i<N;i++)
System.out.print(arr[i]+" ");
System.out.println();
return ;
}
for(int i=0;i<N;i++) {
if(isSelected[i])
continue;
arr[cnt] = i+1;
isSelected[i] = true;
perm(cnt+1);
isSelected[i] = false;
}
}
}
'알고리즘 > 백준' 카테고리의 다른 글
[JAVA]백준_2309_일곱난쟁이 (0) | 2021.02.07 |
---|---|
[JAVA]백준_1302_베스트셀러 (0) | 2021.02.07 |
[JAVA]백준_5597_과제 안 내신 분..? (0) | 2021.02.07 |
[JAVA]백준_2167_별찍기 -6 (0) | 2021.02.07 |
[JAVA]백준_2167_2차원 배열의 합 (0) | 2021.02.07 |