6.2 You are going on a long trip. You start on the road at mile post 0. Along th
ID: 3530692 • Letter: 6
Question
6.2 You are going on a long trip. You start on the road at mile post 0. Along the way there are n hotels, at mile posts A1 < A2 < ... < An , where each Ai is measured from the starting point. The only places you are allowed to stop are at these hotels, but you can choose which of the hotels you stop at. You must stop at the final hotel (at distance An ), which is your destination. You'd ideally like to travel 200 miles a day, but this may not be possible (depending on the spacing of the hotels). If you travel x miles during a day, the penalty for that day is (200 - x)^2 . You want to plan your trip so as to minimize the total penalty.that is, the sum, over all travel days, of the daily penalties. Give an efficient algorithm that determines the optimal sequence of hotels at which to stop.Explanation / Answer
B[k] = be the optimal least penalty spent to reach from A1 to Ak
then
B[k] = min ( B[k-j] + (200 - (A[k]-A[j])^2; for j<k and A[k]-A[j] <200;
the above it the problem formulation for solving by use of dynamic programming.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.