Dynamic Programming – Gas stations with minimum cost problem

There is a car with c litters of gas at the beginning, and the max capacity of gas the car can carry is n litters. There are m gas stations, each represented as 2 integers: p - the coordinate of that gas station, and x - the price of each litter of gas in that gas station.

The car starts at point 0, and needs to go to point d.

Assume that it takes 1 litter of gas per meter

What is the least amount of money to pay to get to point d?

I'm thinking of dynamic programming but don't know where to start.

Read more here: https://stackoverflow.com/questions/68478273/dynamic-programming-gas-stations-with-minimum-cost-problem

Content Attribution

This content was originally published by UTL at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: