Minimum Cost for Tickets
Transitions
On day
i
, if there is an existing ticket covering today, then there is no need to buy any moreOn day
i
, if there are not existing tickets covering today, then we can try buying all three kinds of tickets
A part of the transitions involves keeping track of the duration of the ticket bought.
Top-down
Modelling the transitions, we get:
The recurrence relation is:
Bottom-up
If we intend to buy a ticket on day i
, we cannot be under an existing ticket. So we have to look backwards by (1/7/30) days to find the last time that ticket was bought.
To determine what's the cheapest, we would simply pick the cheapest among the three possible choices when we are looking back.
Hence, the following recurrence relation:
Last updated