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 1≤i≤n,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.)

Get answer to your question and much more