Logic behind Deepak and his journey

The question’s link is
https://online.codingblocks.com/player/12341/content/5197?s=1521

In the given question, i have tried to explore the multiple possibilities but I’m not being able to put it into a code and devise an algorithm. I’m unable to think where to begin from.

Please guide me in the above question.

Hey Suresh , you just need to find the recursive relation for this problem as you know this is an application of Dynamic Programming . Suppose dp[i] denotes the minimum cost required to do this task then for every i in range(n) : you have choices either to choose the current one or don’t take petrol from current one . and you have to choose the minimum of two .
I hope you got the idea behind it . If you find any difficulty in implementing it , feel free to ask for code :blush:

1 Like

sir if we consider the case of:
2 3 4
1 1 3
then it comes out that it is better to get 5 liters of fuel filled at the 0th check point itself instead of going further. So shouldn’t i be checking at every point for the next location where cost at current rate goes higher than the cost of fuel at that particular station and then only fill fuel till that station? likewise doing this for every station and make a bottom up dp?