โœ๏ธ ์ฝ”ํ…Œ ์ค€๋น„/Back Tracking

โœ๏ธ ์ฝ”ํ…Œ ์ค€๋น„/Back Tracking

[๋ฐฑํŠธ๋ž˜ํ‚น / Kotlin] BOJ 14889 - ์Šคํƒ€ํŠธ์™€ ๋งํฌ

๋ฌธ์ œ ํ’€์ด ์–ธ์–ด Kotlin ์ฝ”๋“œ import java.lang.Integer.min import java.util.* import kotlin.math.abs import kotlin.system.exitProcess lateinit var board: Array lateinit var visited: Array var min_value = Int.MAX_VALUE var n = 0 fun main() = with(Scanner(System.`in`)) { n = nextInt() board = Array(n) { Array(n) { nextInt() } } visited = Array(n) { 0 } search(0, 0) println(min_value) } fun search(index: Int,..

โœ๏ธ ์ฝ”ํ…Œ ์ค€๋น„/Back Tracking

[๋ฐฑํŠธ๋ž˜ํ‚น / Kotlin] BOJ 1759 - ์•”ํ˜ธ ๋งŒ๋“ค๊ธฐ

๋ฌธ์ œ ํ’€์ด ์–ธ์–ด Kotlin ์ฝ”๋“œ import java.util.* var l = 0 var c = 0 lateinit var array: Array lateinit var sortedArray: Array lateinit var visited: Array var stringBuilder = StringBuilder() fun main() = with(Scanner(System.`in`)) { l = nextInt() c = nextInt() array = Array(c) { next() } sortedArray = array.sortedArray() visited = Array(c) { 0 } dfs(0, 0) println(stringBuilder) } fun dfs(index: Int, depth:..

โœ๏ธ ์ฝ”ํ…Œ ์ค€๋น„/Back Tracking

[๋ฐฑํŠธ๋ž˜ํ‚น / Kotlin] BOJ 1987 - ์•ŒํŒŒ๋ฒณ

๋ฌธ์ œ ํ’€์ด ์–ธ์–ด Kotiln ์ฝ”๋“œ import java.lang.Integer.max import java.util.* var n = 0 var m = 0 var max_value = 0 val dx = listOf(-1, 1, 0, 0) val dy = listOf(0, 0, -1, 1) lateinit var board: Array lateinit var check: Array fun main() = with(Scanner(System.`in`)) { n = nextInt() m = nextInt() board = Array(n) { Array(m) { "" } } check = Array(26) { 0 } for (i in 0 until n) { val s = next().chunked(1) for..

โœ๏ธ ์ฝ”ํ…Œ ์ค€๋น„/Back Tracking

[๋ฐฑํŠธ๋ž˜ํ‚น / Kotlin] BOJ 14888 - ์—ฐ์‚ฐ์ž ๋ผ์›Œ๋„ฃ๊ธฐ

๋ฌธ์ œ ํ’€์ด ์–ธ์–ด kotlin ์ฝ”๋“œ import java.lang.Integer.max import java.lang.Integer.min import java.util.* var n = 0 var max_value = Int.MIN_VALUE var min_value = Int.MAX_VALUE lateinit var array: Array lateinit var operator: Array fun main() = with(Scanner(System.`in`)) { n = nextInt() array = Array(n) { nextInt() } operator = Array(4) { nextInt() } calculate(array[0], 1) println(max_value) println(min_va..

โœ๏ธ ์ฝ”ํ…Œ ์ค€๋น„/Back Tracking

[๋ฐฑํŠธ๋ž˜ํ‚น / Kotlin] BOJ 2580 - ์Šค๋„์ฟ 

๋ฌธ์ œ ํ’€์ด ์–ธ์–ด Kotlin ์ฝ”๋“œ import java.util.* import kotlin.system.exitProcess lateinit var board: Array fun main() = with(Scanner(System.`in`)) { board = Array(9) { Array(9) { 0 } } // ์ฃผ์–ด์ง„ ๋ฐฐ์—ด์„ ์ž…๋ ฅ๋ฐ›์Œ for (i in 0 until 9) { for (j in 0 until 9) { board[i][j] = nextInt() } } // (0, 0) ๋ถ€ํ„ฐ ์‹œ์ž‘ sudoku(0, 0) } fun check(row: Int, col: Int, value: Int): Boolean { // 1. ๊ฐ™์€ ํ–‰, ๋‹ค๋ฅธ ์—ด์— ๊ฐ™์€ ๊ฐ’์ด ์กด์žฌํ•˜๋Š”์ง€ ํ™•์ธ for (i in 0 unti..

โœ๏ธ ์ฝ”ํ…Œ ์ค€๋น„/Back Tracking

[๋ฐฑํŠธ๋ž˜ํ‚น / Kotlin] BOJ 9663 - N Queen

๋ฌธ์ œ ํ’€์ด ์–ธ์–ด Kotlin ์ฝ”๋“œ import java.util.* import kotlin.math.abs lateinit var array: Array var n = 0 var cnt = 0 fun main() = with(Scanner(System.`in`)) { n = nextInt() array = Array(n) { 0 } nQueen(0) println(cnt) } fun nQueen(depth: Int) { // depth๋Š” row if (depth == n) { println(depth) cnt++ return } for (i in 0 until n) { // i๋Š” col array[depth] = i if (check(depth)) { nQueen(depth + 1) } } } fun ..

โœ๏ธ ์ฝ”ํ…Œ ์ค€๋น„/Back Tracking

[๋ฐฑํŠธ๋ž˜ํ‚น / Kotlin] BOJ 15649 ~ 15652 - N๊ณผ M (1 ~ 4)

N๊ณผ M (1) ๋ฌธ์ œ ํ’€์ด ์–ธ์–ด Kotlin ์ฝ”๋“œ import java.util.* lateinit var visit: Array lateinit var input: Array var n: Int = 0 var m: Int = 0 fun main() = with(Scanner(System.`in`)) { n = nextInt() m = nextInt() visit = Array(n + 1) { 0 } input = Array(n + 1) { 0 } dfs(0) } fun dfs(depth: Int) { if (depth == m) { for (i in 0 until m) { print("${input[i]} ") } println() return } for (i in 0 until n) { if (vis..

kodo_o
'โœ๏ธ ์ฝ”ํ…Œ ์ค€๋น„/Back Tracking' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๊ธ€ ๋ชฉ๋ก