complete 2156.kt and 11727.kt & queue 11058.kt

This commit is contained in:
2024-05-25 17:56:42 +09:00
parent 8031759e0f
commit e4102d91c5
3 changed files with 56 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
val Mem = Array<Int>(1001) { i ->
if (i == 1) {
1
} else if (i == 2) {
3
} else {
0
}
}
fun get(N: Int): Int {
if (Mem[N] != 0) {
return Mem[N]
} else {
Mem[N] = (get(N - 1) + 2 * get(N - 2)) % 10007
return Mem[N]
}
}
fun main() {
val N = readln().toInt()
println(get(N))
}

View File

@@ -0,0 +1,24 @@
fun solve(N: Int, A: Array<Int>): Int {
val T = Array<Triple<Int, Int, Int>>(N) {
Triple(0, 0, 0)
} // 0 안 마시기 ,1번째 마시기, 2번째 마시기
T[0] = Triple(0, A[0], 0)
for (i in 1 until N) {
T[i] = Triple(
maxOf(T[i - 1].first, T[i - 1].second, T[i - 1].third), T[i - 1].first + A[i], T[i - 1].second + A[i]
)
}
return maxOf(T[N - 1].first, T[N - 1].second, T[N - 1].third)
}
fun main() {
val N = readln().toInt()
val A = Array<Int>(N) {
readln().toInt()
}
println(solve(N, A))
}