Course Hero Logo

Shady spots you are going on a very long run of r

Course Hero uses AI to attempt to automatically extract content from documents to surface to you and others so you can study better, e.g., in search results, to enrich docs, and more. This preview shows page 9 - 11 out of 11 pages.

Shady spotsYou are going on a very long run ofRmiles. Luckily, there are some shady spots along theway at which you can stop to rest, at distancesd1< d2<· · ·< dnfrom the starting point. Some ofthese have more shade than others: the benefit you get from stopping at theith spot isbi.You would like to plan your stops so that you get as much total benefit as possible, subject to theconstraint that you run at leastDmiles between stops (and alsoDmiles before your first stop, andalsoDmiles between your last stop and the final destination).For example, supposeR= 10,D= 3, and there aren= 6 stops at distancesd[1 : 6] = [2,3,4,6,7,8]with benefitsb[1 : 6] = [10,10,30,5,30,40]. Then the optimal solution is to stop at locations 3,5, withtotal benefit 60.(a) [2 pts] Write down a formal specification of the problem, by writing down the following:1. Instance2. Solution format3. Constraints4. Objective functionSolution:(b) [2 pts] Here’s a subproblem that can be used for a dynamic programming solution: for 1in,defineB[i] = optimal benefit if you start at positiond[i].For instance, in the example above,B[5] = 0 since if you begin at positiond[5] = 7, then you are notallowed to make any stops before the run is over.For convenience, also defineB[0] to be the optimal benefit starting at position 0.Give the full arrayB[0 : 6] for the example above.Solution:(c) [1 pt] For a general instance withnresting spots, in what order should the subproblemsB[0], B[1], . . . , B[n] be solved?Solution:(d) [4 pts] Give a rule by which the answer to any subproblemB[i] can be determined once answersare known for ”smaller” subproblems (in terms of the ordering from part (c)). Write down a dynamicprogramming algorithm that implements this rule and returns the optimal score. (You do not need toreturn the chosen locations.)Solution:(e) [1 pt] What is the running time of your algorithm? (No need to justify.)
Page 9
Drink breaksYou are going on a bike ride that is a total ofMmiles. You can ride at mostSmiles withouttaking a snack break.Luckily, there are some snack shops along the way, at distancesm1< m2<· · ·< mnfrom the starting point. Buying a drink at theith shop costsdi.At which snack shops should you stop so as to complete the ride while paying as little as possible?You may assume that there is a solution: that is, the distance between consecutive shops is at mostSandm1SandM-mnS.For example, supposeM= 100,S= 30, and there aren= 6 snack shops at distancesm[1 : 6] =[20,30,40,60,70,80] with costsd[1 : 6] = [10,50,15,25,30,50]. Then the optimal solution is to stop atlocations 1,3,5, with total cost 55.(a) [2 pts] Write down a formal specification of the problem, by writing down the following:1. Instance2. Solution format3. Constraints4. Objective functionSolution:

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 11 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Fall
Professor
staff
Tags
Dynamic Programming, Optimization, John Muir, Stop consonant, ith station

Newly uploaded documents

Show More

Newly uploaded documents

Show More

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture