# Tour de France problem : Dynamic programming

Here is the question:

You are doing the Tour de France and you are given a map with all the n places where you can refill your water bottles. Your bottles fit 2 liters of water with which are enough for m kilometres. Your goal is to stop as few times as possible to refill your bottles, since you care about a good time for the Tour de France. Design an efficient algorithm using dynamic programming, prove its correctness and analysis its run time. Give the one-dimensional array A. And the time complexity of filling your array.

I just confuse about this question. And what is the motivation to use dynamic programming.I think it looks like bin packing problem without change the order of choice. Why not use greedy next fit approach(e.g refill at kth station if we can't reach k+1th station without refill)could someone give some hint? Thanks

• Because dynamic programming returns optimal solution, don't you think so? – rus9384 Sep 13 '17 at 23:49
• @rus9384 I have no idea right now how to do it with dp , but why is the greedy do not get optimal. – hahahaha Sep 14 '17 at 0:03
• You could try to find counterexample. This problem is probably not in $\mathsf P$. – rus9384 Sep 14 '17 at 0:17
• Do you have a proof that your greedy algorithm always returns the optimal answer? Have you tried testing it with random testing (see cs.stackexchange.com/q/59964/755)? – D.W. Sep 14 '17 at 0:19