From fd9e9539784b4625b85a392f69b8fb6fc1bdd18b Mon Sep 17 00:00:00 2001 From: Yago Marques Date: Fri, 7 Oct 2022 16:56:37 -0300 Subject: [PATCH] =?UTF-8?q?Solu=C3=A7=C3=A3o=20em=20Python3=20da=20quest?= =?UTF-8?q?=C3=A3o=20983=20-=20Minimum=20Cost=20For=20Tickets?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- python/983_Minimum_Cost_For_Tickets.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 python/983_Minimum_Cost_For_Tickets.py diff --git a/python/983_Minimum_Cost_For_Tickets.py b/python/983_Minimum_Cost_For_Tickets.py new file mode 100644 index 0000000..27bffd5 --- /dev/null +++ b/python/983_Minimum_Cost_For_Tickets.py @@ -0,0 +1,19 @@ +class Solution: + def mincostTickets(self, days: List[int], costs: List[int]) -> int: + @functools.lru_cache(None) + def dp(i, cost_cover_till_day): + + if i >= len(days): + return 0 + + if days[i] <= cost_cover_till_day: + return dp(i+1, cost_cover_till_day) + else: + one_day_cost = costs[0] + dp(i+1, days[i]) + seven_day_cost = costs[1] + dp(i+1, days[i]+6) + thirty_day_cost = costs[2] + dp(i+1, days[i]+29) + + return min(one_day_cost, seven_day_cost, thirty_day_cost) + + + return dp(0, 0) \ No newline at end of file