-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMain.java
42 lines (35 loc) · 962 Bytes
/
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import java.util.Scanner;
import static java.lang.Math.abs;
public class Main {
private static int N;
private static int[] col;
private static int res = 0;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
N = sc.nextInt();
col = new int[N];
sol(0);
System.out.println(res);
}
public static void sol(int depth) {
if (depth == N) {
res += 1;
return;
}
for (int i = 0; i < N; i ++) {
col[depth] = i;
if (CheckConflict(depth)){
sol(depth + 1);
}
}
}
public static boolean CheckConflict(int row){
for (int i = 0; i < row; i++) {
// 열 체크
if (col[row] == col[i]) return false;
// 대각선 체크
if (abs(col[row] - col[i]) == (row - i)) return false;
}
return true;
}
}