Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
isaiahliu committed Dec 25, 2024
1 parent 661ee93 commit 0956d7b
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/main/kotlin/p32xx/Problem3218.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ fun main() {
}

fun dfs(hRange: IntRange, vRange: IntRange): Int {
if (cache[hRange.first][hRange.last - hRange.first + 1][vRange.first][vRange.last - vRange.first + 1] < 0) {
val hSize = hRange.last - hRange.first + 1
val vSize = vRange.last - vRange.first + 1

if (cache[hRange.first][hSize][vRange.first][vSize] < 0) {
var min = Int.MAX_VALUE

hRange.forEach {
Expand All @@ -27,10 +30,10 @@ fun main() {
min = minOf(min, verticalCut[it] + dfs(hRange, vRange.first until it) + dfs(hRange, it + 1..vRange.last))
}

cache[hRange.first][hRange.last - hRange.first + 1][vRange.first][vRange.last - vRange.first + 1] = min
cache[hRange.first][hSize][vRange.first][vSize] = min
}

return cache[hRange.first][hRange.last - hRange.first + 1][vRange.first][vRange.last - vRange.first + 1]
return cache[hRange.first][hSize][vRange.first][vSize]
}

return dfs(horizontalCut.indices, verticalCut.indices)
Expand Down

0 comments on commit 0956d7b

Please sign in to comment.