mincost tickets

🏠
 1def mincostTickets(days, costs):
 2    dp = [0] * 366
 3    days_set = set(days)
 4    for d in range(366):
 5        if d not in days_set:
 6            dp[d] = dp[d - 1]
 7        else:
 8            mincost = dp[d - 1] + costs[0]
 9            mincost = min(mincost, dp[max(0, d - 7)] + costs[1])
10            mincost = min(mincost, dp[max(0, d - 30)] + costs[2])
11            dp[d] = mincost
12    return dp[-1]
13
14
15print(mincostTickets([1, 4, 6, 7, 8, 20], [2, 7, 15]))