Suppose we are going to travel from A to B, during the travel, there are some stations, d_1,...,d_n where d_1=A, d_n=B, we have the choice to add fuel at each station with cost C_i, suppose if we add gas at station d_i, then we can travel a_i more kilometers. I want to find a dynamic programming algorithm to find the minimum cost to travel to B(suppose such a sequence exists).
I try to use D[i] as the minimum cost of traveling to station i from A, but I am in trouble with figuring out the recurrence relationship. i think i may need to keep track of how long we can travel currently. But that will be too complicated...