Skip to content

Commit 829506a

Browse files
committed
[BOJ] #9633. NQueen / 골드4 / 50분 (실패)
https://www.acmicpc.net/problem/9663
1 parent 5c18ba1 commit 829506a

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# pypy3로 통과
2+
3+
import sys
4+
input = sys.stdin.readline
5+
6+
# 유망한지 판단하는 함수
7+
def isPromissing(board, new):
8+
for i in range(new):
9+
10+
# 같은 열이면 안 되고, 대각선상에 있어서도 안 된다.
11+
if board[new] == board[i] or new - i == abs(board[new]-board[i]):
12+
return 0
13+
return 1
14+
15+
# N Queen 알고리즘 수행
16+
def nQueen(new, board):
17+
global n
18+
global count
19+
print(board)
20+
# n 이 마지막행까지 수행하고 여기까지 오면 찾기 완료!
21+
if new == n:
22+
count += 1
23+
return
24+
for i in range(n):
25+
board[new] = i
26+
if isPromissing(board, new):
27+
nQueen(new + 1, board)
28+
29+
count = 0
30+
board = [0] * 15
31+
n = int(input())
32+
nQueen(0, board)
33+
print(count)

0 commit comments

Comments
 (0)