-
Notifications
You must be signed in to change notification settings - Fork 0
/
solution.kt
31 lines (29 loc) · 968 Bytes
/
solution.kt
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
fun main(args: Array<out String>) {
fun makeWParam(a: Int, b: Int, c: Int): Int = (a * 100 + b) * 100 + c
val dp = mutableMapOf<Int, Int>()
fun w(a: Int, b: Int, c: Int): Int {
if (a <= 0 || b <= 0 || c <= 0) {
return 1
}
if (a > 20 || b > 20 || c > 20) {
return w(20, 20, 20)
}
val key = makeWParam(a, b, c)
if (key !in dp) {
dp[key] = if (a < b && b < c) {
w(a, b, c - 1) + w(a, b - 1, c - 1) - w(a, b - 1, c)
} else {
w(a - 1, b, c) + w(a - 1, b - 1, c) + w(a - 1, b, c - 1) - w(a - 1, b - 1, c - 1)
}
}
return dp[key]!!
}
System.`in`
.bufferedReader()
.lineSequence()
.takeWhile { it != "-1 -1 -1" }
.joinToString("\n") {
val (a, b, c) = it.split(" ").map { it.toInt() }
"w($a, $b, $c) = ${w(a, b, c)}"
}.let(::println)
}