Compy's Blog
53 words
1 minutes
[NYPC] 1차 3번 커닝시티 헤어샵
2024-11-06

pro

기본적인 dp 문제

def solution():
    n = int(input())

    time_table = list(map(int, input().split()))

    dp = [float('inf')] * (n+1)

    dp[0] = time_table[0]
    if n == 1: return dp[0]

    dp[1] = min(max(time_table[0], time_table[1]), dp[0] + time_table[1])

    for i in range(2, n):
        dp[i] = min(dp[i-1]+time_table[i], max(time_table[i], time_table[i-1]) + dp[i-2])
    return dp[n-1]
print(solution())
[NYPC] 1차 3번 커닝시티 헤어샵
https://compy07.github.io/Blog/posts/algorithms/nypc/2024/first/3/
Author
뒹굴뒹굴 이정훈 공부방
Published at
2024-11-06