Question: 2. (15, Dynamic Programming) You have n envelopes arranged in a line in front of you, and on the top of each envelope is written

 2. (15, Dynamic Programming) You have n envelopes arranged in a

2. (15, Dynamic Programming) You have n envelopes arranged in a line in front of you, and on the top of each envelope is written a number that indicates the amount of dollars it contains. You can choose to pick as many envelopes as you want, but you are not allowed to take neighboring envelopes. You want to select the envelopes to make the most (total) money. For example, if the envelopes are E=[100,50,100,50,150,125,25,5,1,75], I can pick envelopes 1,3,5,7,10. Note I did not pick the E[6]=125 envelope. Give an O(n) algorithm that outputs the maximum amount of money possible by selecting envelopes from a given array E. You can use ideas from any problem we have seen in class, but you must write your pseudocode

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!