IT/알고리즘
[백준] 카드구매하기
남갯
2024. 11. 21. 19:44
728x90
SMALL
https://www.acmicpc.net/problem/11052
fun main() = with(Scanner(System.`in`)) {
val count = nextInt()
val array: Array<Int> = Array(count) { 0 }
for (i in 0 until count) {
array[i] = nextInt()
}
val dp = Array(array.size + 1) { 0 }
for (i in array.indices) {
dp[i + 1] = array[i]
}
for (i in 1 .. count) {
for (j in 1 .. i) {
dp[i] = max(dp[i], dp[i - j] + dp[j])
}
}
println(dp[count])
}
728x90
LIST