Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 코딩테스트
- 알고리즘
- 백준
- vscode
- 네이버AItech
- rnn
- NLP
- pep8
- 프로그래머스
- NaverAItech
- github
- GCP
- leetcode
- GitHub Action
- pytorch
- autoencoder
- Kaggle
- datascience
- GIT
- Matplotlib
- FastAPI
- DeepLearning
- torchserve
- 완전탐색
- PytorchLightning
- python
- FDS
- docker
- wandb
- Kubernetes
Archives
- Today
- Total
Sangmun
n-queen 본문
https://www.acmicpc.net/problem/9663
9663번: N-Queen
N-Queen 문제는 크기가 N × N인 체스판 위에 퀸 N개를 서로 공격할 수 없게 놓는 문제이다. N이 주어졌을 때, 퀸을 놓는 방법의 수를 구하는 프로그램을 작성하시오.
www.acmicpc.net
def adjacent(x):
for i in range(x):
if row[x] == row[i] or abs(row[x] - row[i]) == x - i:
return False
return True
def dfs(x):
global result
if x == N:
result += 1
else:
for i in range(N):
row[x] = i
if adjacent(x):
dfs(x + 1)
N = int(input())
row = [0] * N
result = 0
dfs(0)
print(result)
'알고리즘 > 백준' 카테고리의 다른 글
백준 16953번 A -> B (0) | 2022.12.08 |
---|---|
백준 1094번 막대기 (0) | 2022.12.07 |
백준 1647번 도시분할 계획 (0) | 2022.11.20 |
백준 11779번 최소비용 구하기 2 (0) | 2022.11.20 |
백준 11758번 CCW (0) | 2022.11.10 |
Comments