dp
array with a size of the last day we need to travel plus 1
, all values set to 0
.i = 0
, representing the index for the next travel day in days
.1
to the last day in days
.
day
is less than days[i]
, set dp[day]
to dp[day - 1]
.dp[day]
as the minimum of dp[day - 1] + costs[0]
, dp[max(day - 7, 0)] + costs[1]
, and dp[max(day - 30, 0)] + costs[2]
. Increment i
.dp[lastDay]
, where lastDay
is the last value in days
.