Suppose you\'re managing a consulting team of expert computer backers, and each
ID: 3732273 • Letter: S
Question
Suppose you're managing a consulting team of expert computer backers, and each week you have to choose a job for them to undertake. Now, as you can well imagine, the set of possible jobs is divided into those that are low-stress (e-g, setting up a Web site for a class at the local elementary school) and those that are high-stress (e.g., protecting the nation's most valuable secrets, or helping a desperate group of Cornell students finish a project that has something to do with compilers). The basic question, each week, is whether to take on a low-stress job or a high-stress job If you select a low-stress job for your team in week i, then you get a revenue of 4>0 dollars; if you select a high-stress job, you get a revenue of hy>0 dollars. The catch, however, is that in order for the team to take on a high-stress job in week i, it's required that they do no job (of either type) in week -1;they need a full week of prep time to get ready for the crushing stress level. On the other hand, it's okay for them to take a low- stress job in week i even if they have done a job (of either type) in week So, given a sequence of n weeks, a plan is specified by a choice of "Sow-stress," "high-stress," or "none" for each of the n weeks, with the property that if "high-stress" is chosen for week i>1, then "none" has to be chosen for week i-1. at's okay to choose a high-stress job in week 1.) The value of the plan is determined in the natural way: for each i, you add 4 to the value if you choose "low-stress" in week i, and you add h, to the value if you choose "high-stress" in week i. (You add 0 if you choose none" in week i) The problem. Given sets of values and hy,h. .h, finda plan of maximum value. (Such a plan will be called optimal.) Example. Suppose n-4, and the values of and hy are given by the following table. Then the plan of maximum value would be to choose none" in week 1, a high-stress job in week 2, and low-stress jobs in weeks 3 and 4. The value of this plan would be 0+50+10+10-70 Week 1 Week 2 Week 3 Week 4 10 10 50Explanation / Answer
This solution will fail when suppose in current iteration li + li+1 > hithus li is chosen and in the next iteration li + li+1 < hithus hi should be chosen in this iteration but since last iteration was not 'none' high-stress job cannot be chosen, the algorithm will fail.
This problem can be solved using dynamic programming, by splitting the problem into sub-problems and solving them recursively as:
rev(0) = 0
rev(1) = max(l1, h1)
rev(i) = max[(li + rev(i1)),(hi + rev(i2))]
The silution is defined as: rev(0) means revenue generated by working 0 weeks, which will be 0 as no work has been performed. Now rev(1) should be maximum of low or high stress jobs. Now for i>1, rev() depends on rev() of i-1 & i-2. If we choose high stress job in ith iteration then check for rev() in i-2 iteration since rev() of i-1 will be none and if we choose low stress in ith iteration then check fo rev for i-1 iteration. Compare these two values and take maximum of them. This solution is similar to fibonacci series.
rev(n):
if n=0: return 0;
if n=1: return max(l1,h1)
return max[(li + rev(i1)),(hi + rev(i2))]
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.