From 3553f9c1b5c68d1ff337c7899d59d2f0402be60e Mon Sep 17 00:00:00 2001 From: vrexpert Date: Sun, 19 May 2024 00:38:40 +0900 Subject: [PATCH 1/3] 2024-05-18 update README.md --- SeongHoonC/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SeongHoonC/README.md b/SeongHoonC/README.md index 4d2959be..97f7017b 100644 --- a/SeongHoonC/README.md +++ b/SeongHoonC/README.md @@ -24,5 +24,6 @@ | 20차시 | 2024.04.07 | DP | |https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/75 | | 21차시 | 2024.04.11 | DP | RGB거리 |https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/77 | | 22차시 | 2024.05.01 | DP | 가장 긴 증가하는 부분 수열 |https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/80 | -| 23차시 | 2024.05.14 | ??? | 소수의 연속합 |https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/186 | +| 23차시 | 2024.05.14 | 소수 | 소수의 연속합 |https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/186 | +| 24차시 | 2024.05.18| ??? | n-queen |https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/192 | --- From ea14deedca2bab3d7546e3031c6a40136651c952 Mon Sep 17 00:00:00 2001 From: vrexpert Date: Sun, 19 May 2024 20:03:03 +0900 Subject: [PATCH 2/3] 2024-05-19 solved --- SeongHoonC/dfs/nqeen.kt | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 SeongHoonC/dfs/nqeen.kt diff --git a/SeongHoonC/dfs/nqeen.kt b/SeongHoonC/dfs/nqeen.kt new file mode 100644 index 00000000..aa11ddf5 --- /dev/null +++ b/SeongHoonC/dfs/nqeen.kt @@ -0,0 +1,41 @@ +import java.io.BufferedReader +import java.io.InputStreamReader + +var answer = 0 +var n: Int = 0 +lateinit var board: IntArray +fun main() { + val br = BufferedReader(InputStreamReader(System.`in`)) + n = br.readLine().toInt() + board = IntArray(n) + backTracking(0) + println(answer) +} + +private fun backTracking(row: Int) { + // row 가 증가하다가 n 이랑 같아지면 정답 +1 + if (row == n) { + answer++ + return + } + // row 일 때 각 열에 놓을 경우의 수 + for (col in 0 until n) { + board[row] = col + // 놓을 수 있다면 다음 행 + if (check(row)) backTracking(row + 1) + } +} + +private fun check(row: Int): Boolean { + for (i in 0 until row) { + // 행이 같거나 + if (board[row] == board[i]) { + return false + } + // 대각선 + if (row - i == kotlin.math.abs(board[row] - board[i])) { + return false + } + } + return true +} From 982369ad42060181accc32311a12a446273300aa Mon Sep 17 00:00:00 2001 From: vrexpert Date: Wed, 22 May 2024 16:08:33 +0900 Subject: [PATCH 3/3] =?UTF-8?q?2024-05-18=20=EB=AC=B8=EC=A0=9C=20=EC=97=85?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SeongHoonC/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SeongHoonC/README.md b/SeongHoonC/README.md index 97f7017b..e8dbcae8 100644 --- a/SeongHoonC/README.md +++ b/SeongHoonC/README.md @@ -25,5 +25,5 @@ | 21차시 | 2024.04.11 | DP | RGB거리 |https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/77 | | 22차시 | 2024.05.01 | DP | 가장 긴 증가하는 부분 수열 |https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/80 | | 23차시 | 2024.05.14 | 소수 | 소수의 연속합 |https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/186 | -| 24차시 | 2024.05.18| ??? | n-queen |https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/192 | +| 24차시 | 2024.05.18| 백트래킹 | n-queen |https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/192 | ---