Untitled
class Solution: def mincostTickets(self, days: List[int], costs: List[int]) -> int: def rec(i,d): if i>=len(days): return 0 if d>days[len(days)-1]: return 0 while(i<len(days) and days[i]<=d): i+=1 if (i,d) not in dp: a=costs[0]+rec(i+1,d+1) b=costs[1]+rec(i+1,d+7) c=costs[2]+rec(i+1,d+30) dp[(i,d)]= min(min(a,b),c) return dp[(i,d)] dp={} return rec(0,0)
Leave a Comment