diff --git a/백준/Gold/9663. N-Queen/N-Queen.py b/백준/Gold/9663. N-Queen/N-Queen.py new file mode 100644 index 0000000..098e09c --- /dev/null +++ b/백준/Gold/9663. N-Queen/N-Queen.py @@ -0,0 +1,37 @@ +import sys + +input = sys.stdin.readline + +n = int(input().strip()) + +colUsed = [False] * (n) +diagUsed = [False] * ((2*n)-1) +AntidiagUsed = [False] * ((2*n)-1) + +tot = 0 + +def placeQueens(row): + global tot + + if (row == n): + tot+=1 + return + + for col in range(n): + diagIndex = row - col + n - 1 + AntiDiagIndex = row + col + + if not colUsed[col] and not diagUsed[diagIndex] and not AntidiagUsed[AntiDiagIndex]: + colUsed[col] = True + diagUsed[diagIndex] = True + AntidiagUsed[AntiDiagIndex] = True + + placeQueens(row + 1) + + colUsed[col] = False + diagUsed[diagIndex] = False + AntidiagUsed[AntiDiagIndex] = False + + +placeQueens(0) +print(tot) diff --git a/백준/Gold/9663. N-Queen/README.md b/백준/Gold/9663. N-Queen/README.md new file mode 100644 index 0000000..825f6cf --- /dev/null +++ b/백준/Gold/9663. N-Queen/README.md @@ -0,0 +1,30 @@ +# [Gold IV] N-Queen - 9663 + +[문제 링크](https://www.acmicpc.net/problem/9663) + +### 성능 요약 + +메모리: 32412 KB, 시간: 29720 ms + +### 분류 + +백트래킹, 브루트포스 알고리즘 + +### 제출 일자 + +2025년 3월 11일 14:02:42 + +### 문제 설명 + +
N-Queen 문제는 크기가 N × N인 체스판 위에 퀸 N개를 서로 공격할 수 없게 놓는 문제이다.
+ +N이 주어졌을 때, 퀸을 놓는 방법의 수를 구하는 프로그램을 작성하시오.
+ +### 입력 + +첫째 줄에 N이 주어진다. (1 ≤ N < 15)
+ +### 출력 + +첫째 줄에 퀸 N개를 서로 공격할 수 없게 놓는 경우의 수를 출력한다.
+