Skip to content

Commit

Permalink
#45 9663.py
Browse files Browse the repository at this point in the history
  • Loading branch information
HanMulBit committed Sep 3, 2024
1 parent c90adad commit 0eee9fb
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions aiden/class4-2/9663.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
def safe(row, col):
for i in range(row):
if col == queens[i] or abs(col - queens[i]) == row - i:
return False
return True

def near_queens(row):
global count # 전역 변수 count를 사용하겠다는 선언
# 사용 시 def 함수 외에서 선언된 변수를 내부에서 사용 가능
if row == n:
count += 1
return
for col in range(n):
if not col_used[col] and not diag1_used[row + col] and not diag2_used[row - col + n - 1]:
col_used[col] = diag1_used[row + col] = diag2_used[row - col + n - 1] = True
near_queens(row + 1)
col_used[col] = diag1_used[row + col] = diag2_used[row - col + n - 1] = False

n = int(input())
col_used = [False] * n
diag1_used = [False] * (2 * n - 1)
diag2_used = [False] * (2 * n - 1)
count = 0
near_queens(0)
print(count)

0 comments on commit 0eee9fb

Please sign in to comment.