IT/알고리즘
[백준] 퇴사
남갯
2024. 11. 12. 20:13
SMALL
https://www.acmicpc.net/problem/14501
fun main() = with(Scanner(System.`in`)) {
val count = nextInt()
val days: MutableList<Days> = mutableListOf()
for (i in 0 until count) {
val day = nextInt()
val pay = nextInt()
days.add(Days(day, pay))
}
var result = 0
fun dfs(totalDays: Int, pay: Int) {
if (totalDays <= count) {
result = max(result, pay)
}
for (i in totalDays until count) {
if (i + days[i].day > count) continue
dfs(i + days[i].day, pay + days[i].pay)
}
}
dfs(totalDays = 0, pay = 0)
println(result)
}
data class Days(val day: Int, val pay: Int)
LIST