[12 marks] Dynamic programming In the NUGGETSINSWAMP problem, the input is an array W of n...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
[12 marks] Dynamic programming In the NUGGETSINSWAMP problem, the input is an array W of n positive integers W[1], ..., W[n] representing the weights of nuggets lying on your path in a swamp. You would like to pick up some of the nuggets maximizing the total weight (which is your profit). Bad news is - you cannot pick up two adjacent nuggets. The valid solution for this problem is the largest possible weight of nuggets that can be obtained by picking up a subset of the entries of W such that the subset contains at most one of any two consecutive entries W[i], W[i+1] for every 1 ≤ i ≤ n - 1. For example, given array W=[4,6,7,1,5], the maximum weight that satisfies constraints is W[1] + W[3] + W[5] = 4 + 7 + 5 = 16, while W[2] + W[3] + W[5] = 6 + 7 + 5 = 18 does not satisfy constraints as it picks two consecutive entries W[2], W[3]. In this question, you will design and analyze a dynamic programming algorithm that solves the NUGGETSINSWAMP problem. (a) Provide an example of input to show that in some cases, the optimal solution can skip two consecutive entries in the array. (b) Give an example of input to show that the greedy algorithm of choosing the entries in order of decreasing weight (from largest to smallest while satisfying constrains) does not always give the best solution. (c) Give a precise definition of a subproblem that can be used to solve the NUGGETSINSWAMP problem with a dynamic programming algorithm. What is the quantity associated with this subproblem? [12 marks] Dynamic programming In the NUGGETSINSWAMP problem, the input is an array W of n positive integers W[1], ..., W[n] representing the weights of nuggets lying on your path in a swamp. You would like to pick up some of the nuggets maximizing the total weight (which is your profit). Bad news is - you cannot pick up two adjacent nuggets. The valid solution for this problem is the largest possible weight of nuggets that can be obtained by picking up a subset of the entries of W such that the subset contains at most one of any two consecutive entries W[i], W[i+1] for every 1 ≤ i ≤ n - 1. For example, given array W=[4,6,7,1,5], the maximum weight that satisfies constraints is W[1] + W[3] + W[5] = 4 + 7 + 5 = 16, while W[2] + W[3] + W[5] = 6 + 7 + 5 = 18 does not satisfy constraints as it picks two consecutive entries W[2], W[3]. In this question, you will design and analyze a dynamic programming algorithm that solves the NUGGETSINSWAMP problem. (a) Provide an example of input to show that in some cases, the optimal solution can skip two consecutive entries in the array. (b) Give an example of input to show that the greedy algorithm of choosing the entries in order of decreasing weight (from largest to smallest while satisfying constrains) does not always give the best solution. (c) Give a precise definition of a subproblem that can be used to solve the NUGGETSINSWAMP problem with a dynamic programming algorithm. What is the quantity associated with this subproblem?
Expert Answer:
Answer rating: 100% (QA)
a Input W10 5 8 1 7 6 Optimal solution W1 W4 W6 10 7 6 23 This optimal solution skips two consecutive entries W2 and W3 in the array Algorithm NUGGETS... View the full answer
Related Book For
Introduction to Algorithms
ISBN: 978-0262033848
3rd edition
Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest
Posted Date:
Students also viewed these programming questions
-
The risk index of an investment can be obtained by taking the absolute values of percentage changes in the value of the investment for each year and averaging them. Suppose you are trying to...
-
The equation for determining the sample size can be obtained by solving the equation for the margin of error for n. Show that this is true and justify each step. pa E=-c
-
The highest MA that can be obtained by a system of two pulleys is a. 2 b. 3 c. 4 d. 5
-
In the early part of 2013, the partners of Page, Childers, and Smith sought assistance from a local accountant. They had begun a new business in 2012 but had never used an accountants services. Page...
-
The right side of Figure shows a system that simulates the manufacture of computer chips. The equations in the simulation system are based on statistical probabilities of failures in the...
-
During each year, CSL Computer Company needs to train 27 service representatives. It costs $12,000 to run a training program, regardless of the number of students being trained. Service reps earn a...
-
Assume that Midway Cycles bought and sold a line of mountain bikes during May as follows: Midway Cycles uses the perpetual inventory system. Requirements 1. Compute the cost of ending inventory under...
-
Toledo Custom Manufacturing (TCM) makes machined steel parts to customer specification. They have a variety of machines that can hold tight tolerances. In this case they have just received an order...
-
what is reward to variability ratio? is it sharpe ratio?
-
The marbled murrelet is a seabird on the list of endangered species. Pacific Lumber Co. received permission to harvest trees from land on which the murrelet nested, on the condition that it would...
-
The total demand in Europe and Canada is 1300 tones. The variable cost of NutraSweet is $18 per lb. and the variable cost of HSC is $25. Suppose that the fixed cost is irrelevant. The expected price...
-
Suppose you purchased one share of ABC, Inc for $ 5 7 . 7 5 per share. The company paid a dividend of $ 3 . 2 9 per share during the year , and had an ending share price of $ 5 0 . 7 . What is the...
-
Take a look at how Dove is marketing the product, along with other men's products, in the videos found at: http://www.dovemencare.com/ ("Cleanse with Care", "The Right Shave," and "Moisturize Like a...
-
Gene has earnings of $550.00 this week. His year-to-date Employment Insurance premiums, for 2023, total $1,000.88. Calculate Genes Employment Insurance premium for the current pay period.
-
You borrow $550,000 at 3% APR to purchase a home. You plan to pay off the loan in 30 years with monthly payments of $ 2,310.00 Make an amortization table showing payments over the first three months....
-
In 2 0 2 1 , Black Ivy reported sales of $ 6 , 7 8 3 million, COGS $ 4 , 1 3 6 million, operating expense $ 1 , 6 9 9 million, interest expense $ 1 6 million. What is interest coverage ratio?
-
1) If an investment bank offers both underwriting/distribution functions and investment advisory or management functions, which situation would be acceptable under U.S. Securities and Exchange...
-
Determine the annual percentage yield for a loan that charges a monthly interest rate of 1.5% and compounds the interest monthly.
-
Suppose that an algorithm uses only comparisons to find the i th smallest element in a set of n elements. Show that it can also find the i - 1 smaller elements and the n - i larger elements without...
-
Redo Exercise 17.1-3 using an accounting method of analysis. 17.1-3 Suppose we perform a sequence of n operations on a data structure in which the i th operation costs i if i is an exact power of 2,...
-
What is an optimal Huffman code for the following set of frequencies, based on the first 8 Fibonacci numbers? a:1 b:1 c:2 d:3 e:5 f:8 g:13 h:21 Can you generalize your answer to find the optimal code...
-
Distinguish among the following substantive tests of plant assets and indicate the assertion(s) to which each test pertains: a. Apply analytical procedures. b. Inspect plant assets. c. Examine title...
-
a. Describe the nature of the production cycle. b. Identify the major transaction class within this cycle. c. Name three other cycles that interface with the production cycle.
-
a. Explain several control environment factors that impact the production cycle. b. Identify several unique elements of an entity's accounting information system that pertain to the production cycle.
Study smarter with the SolutionInn App