MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / dynamic_programming

Function dynamic_programming

dynamic_programming/minimum_tickets_cost.py:110–121  ·  view source on GitHub ↗
(index: int)

Source from the content-addressed store, hash-verified

108
109 @functools.cache
110 def dynamic_programming(index: int) -> int:
111 if index > 365:
112 return 0
113
114 if index not in days_set:
115 return dynamic_programming(index + 1)
116
117 return min(
118 costs[0] + dynamic_programming(index + 1),
119 costs[1] + dynamic_programming(index + 7),
120 costs[2] + dynamic_programming(index + 30),
121 )
122
123 return dynamic_programming(1)
124

Callers 1

mincost_ticketsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected