https://www.acmicpc.net/problem/9663
import sys
input = sys.stdin.readline
N = int(input())
ans = 0
row = [0]*N
def is_promising(x):
for i in range(x):
if row[x] == row[i] or abs(row[x] - row[i]) == abs(x - i):
return False
return True
def n_queens(x):
global ans
if x == N:
ans += 1
return
else:
for i in range(N):
# [x, i]에 퀸을 놓음
row[x] = i
if is_promising(x):
n_queens(x+1)
n_queens(0)
print(ans)'코딩테스트 > 코딩테스트 문제풀이' 카테고리의 다른 글
| [Python] 백준 <1062-가르침> (0) | 2025.07.23 |
|---|---|
| [Python] 백준 <1034-램프> (0) | 2025.07.21 |
| [Python] 백준 <14500-테트로미노> (0) | 2025.07.17 |
| [Python] 백준 <2293-동전 1> (0) | 2025.07.16 |
| [Python] 백준 <3190-뱀> (0) | 2025.07.16 |