UVa 10201 - Adventures in Moving - Part IV

10201 - Adventures in Moving - Part IV

 * [Problem Link] : http://online-judge.uva.es/p/v102/10201.html

Summary
You have to find the minimum cost for fuel to get from A to B without running out of fuel. Fuel can be bought from gas stations. Each station is has a distance from city A, and a cost for the fuel.

Explanation
We have to compute the minimum cost to get to city i with j litres of gas. For this we calculate d[i][j] - the cost required. Of course, d[0][100] = 0 (at first, the gas tank is half-full). To calculate d[i][j] we only need the city before (i-1). So    d[i][j] = d[i-1][k-flost+fbought] + c[i]*fbought. where : - flost is the fuel neccesary to get from (i-1) to (i) - fbought is the amount of fuel bought from station (i) - c[i] is the gas cost at station (i)

For this, we have to iterate i from 1 to n+1, k from flost to 200 and fbought from 0 to 200, resultin a complexity of O(40000 * n)

Gotchas

 * Any points one can easily overlook?
 * The correct way to understand ambiguous formulations?

Implementations
Notes/Hints on actual implementation here.

Optimizations
Optimizations here.

Input
Input Here

Output
Output Here