본문 바로가기

IT/알고리즘

[백준] 퇴사

728x90
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)
728x90
LIST

'IT > 알고리즘' 카테고리의 다른 글

[백준] 2xn 타일링2  (0) 2024.11.18
[백준] 차이를 최대로  (0) 2024.11.14
[백준] 좋은수열  (0) 2024.11.11
[백준] 단어수학  (2) 2024.11.11
[프로그래머스] 3xn 타일링  (0) 2024.11.11