diff --git a/froglike6/README.md b/froglike6/README.md index 10a4874..51f5436 100644 --- a/froglike6/README.md +++ b/froglike6/README.md @@ -7,4 +7,5 @@ | 3차시 | 2025.03.24 | 정수 | [피보나치 수와 최대공약수](https://www.acmicpc.net/problem/11778)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/9| | 4차시 | 2025.03.30 | 그래프 | [친구](https://www.acmicpc.net/problem/1058)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/16| | 5차시 | 2025.04.01 | 정수 | [개구리](https://www.acmicpc.net/problem/25333)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/17| + | 6차시 | 2025.04.07 | 백트래킹| [N-Queen](https://www.acmicpc.net/problem/9663)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/24| --- diff --git a/froglike6/backtracking/9663.py b/froglike6/backtracking/9663.py new file mode 100644 index 0000000..69b1929 --- /dev/null +++ b/froglike6/backtracking/9663.py @@ -0,0 +1,17 @@ +def dfs(row, cols, diag1, diag2): + global count + if row == n: + count += 1 + return + available_positions = (~(cols | diag1 | diag2)) & ((1 << n) - 1) + while available_positions: + position = available_positions & -available_positions + available_positions &= available_positions - 1 + dfs(row + 1, + cols | position, + (diag1 | position) << 1, + (diag2 | position) >> 1) +n = int(input()) +count = 0 +dfs(0, 0, 0, 0) +print(count) \ No newline at end of file