t you are asked to implement a dynamic programming algorithm for the Rod Cutting Problem ....
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
t you are asked to implement a dynamic programming algorithm for the Rod Cutting Problem . In the Rod Cutting problem, you are given an integer n21, along with a sequence of positive prices, P₁ P2. Pn. where p, is the market price of a rod of length i. The goal is to figure out a best way of cutting the given rod of length n to generate the maximum revenue. You can assume that the given prices P1.p2... Pn are all integers. Input The input has the following format. The input starts with n. Then, P₁, P2P₁ follow, one per each line. Output In the first line, output the maximum revenue (rn), followed by an enter key. In the second line, sequentially output the length of each piece in your optimal cutting, followed by a space key. The second line must end by -1 and an enter key. Examples of input and output Input 7 1 5 8 9 10 17 17 Output 18 16-1 The following is the output with white characters shown. 18(enter) 1 (space)6 (space)-1 (enter) Alternatively, the second line can be replaced with "6 1-1", "2 23-1","2 3 2 -1", or "3 2 2-1". That is, any sequence of piece lengths giving the maximum revenue will be considered to t you are asked to implement a dynamic programming algorithm for the Rod Cutting Problem . In the Rod Cutting problem, you are given an integer n21, along with a sequence of positive prices, P₁ P2. Pn. where p, is the market price of a rod of length i. The goal is to figure out a best way of cutting the given rod of length n to generate the maximum revenue. You can assume that the given prices P1.p2... Pn are all integers. Input The input has the following format. The input starts with n. Then, P₁, P2P₁ follow, one per each line. Output In the first line, output the maximum revenue (rn), followed by an enter key. In the second line, sequentially output the length of each piece in your optimal cutting, followed by a space key. The second line must end by -1 and an enter key. Examples of input and output Input 7 1 5 8 9 10 17 17 Output 18 16-1 The following is the output with white characters shown. 18(enter) 1 (space)6 (space)-1 (enter) Alternatively, the second line can be replaced with "6 1-1", "2 23-1","2 3 2 -1", or "3 2 2-1". That is, any sequence of piece lengths giving the maximum revenue will be considered to
Expert 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 algorithms questions
-
Use the data in the accompanying table. The data come from a study of ice cream consumption that spanned the springs and summers of three years. The ice cream consumption is in liters per capita per...
-
As you continue exploring HIPAA's requirements regarding fundraising activities, I wanted to consider the impact--if any--that the COVID-19 pandemic should have on those provisions. All of us can...
-
Chapter 16 Homework Problem #1 The financial statements for Castile Products, Inc. are given below: A Assets Current assets: Castile Products, Inc. Balance Sheet December 31 Cash.... Accounts...
-
A driver of a car is initially 455 miles from home, traveling toward home on a straight freeway at 70 miles per hour. (a) Write a formula for a linear function f that models the distance between the...
-
Determine the horizontal force required to move a 1-Mg automobile with 460-mm-diameter tires along a horizontal road at a constant speed. Neglect all forms of friction except rolling resistance, and...
-
Journalize the following transactions, using the direct write-off method of accounting for uncollectible receivables: Oct. 2. Received $1,140 from Elita Ramirez and wrote off the remainder owed of...
-
Analyze the chemical process data in Table B. 5 for evidence of multicollinearity. Use the variance inflation factors and the condition number of \(\mathbf{X}^{\prime} \mathbf{X}\). Run No. y X x2 X3...
-
1. Take a poll of your class (at least, the Gen-X and Gen-Y members). At school or work, how many regularly (e.g., daily or every few days) send or receive information (not entertainment) using (a)...
-
Solve the following recurrence relations. You may use any method discussed in class, but you need to justify your answers by showing all relevant details. If you use a guess-and-prove method,...
-
John and Sandy Ferguson got married eight years ago and have a seven-year-old daughter, Samantha. In 2020, John worked as a computer technician at a local university earning a salary of $152,000, and...
-
Analyze at least three types of performance appraisals, highlighting the advantages and/or disadvantages of each type. Feel free to share personal experiences or concerns that arise when considering...
-
The PHC is offering a prize of $3,000 per week for 5 years. If the interest rate is 5.2%, compounded weekly, what is the present equivalent value of the prize? What is the future equivalent value at...
-
You are making $500 monthly deposits into a savings account that pays interest at a nominal rate of 6% per year, compounded monthly. What is the future equivalent value of this account after seven...
-
Bill took out a 10 year loan to buy a car. If the loan carried an annual interest rate of 5.2% and he made monthly payments of $345, how much interest did he pay? Round your answer to the nearest...
-
North Bank issued a one-year $2 million CD at 6 percent and is planning to fund a loan in British pounds at 8 percent for a 2 percent expected spread. The spot rate of U.S. dollars for British pounds...
-
You finance a new car with a 7 percent loan for 80 percent of the car value. The ination premium is 3.0 percent. If the risk premium is 2 percent, what is the pure rate using the multiplicative form?
-
5 One type of investment vehicle that can be used to diversify both across and within investment categories is Select one: O O O a. Hedge fund b. Municipal bond c. Mutual fund d. Pooled investment...
-
Why are stocks usually more risky than bonds?
-
Show that edge (u, ) is a. a tree edge or forward edge if and only if u.d < .d < .f < u.f, b. a back edge if and only if .d u.d < u.f .f, and c. a cross edge if and only if .d < .f < u.d < u.f.
-
Draw all the free trees composed of the three vertices x, y, and z. Draw all the rooted trees with nodes x, y, and z with x as the root. Draw all the ordered trees with nodes x, y, and z with x as...
-
Generalize Huffman's algorithm to ternary codewords (i.e., codewords using the symbols 0, 1, and 2), and prove that it yields optimal ternary codes.
-
Which of the following does not occur in the small intestine? (a) Bile from the gall bladder breaks fats into small droplets. (b) Nutrients are absorbed into the body. (c) Proteins are broken down....
-
Which blood vessels are responsible for nutrient and waste exchange with tissues?
-
Trace the path of blood through the body, beginning with blood returning from the tissues to the heart. Be sure to name each of the chambers of the heart.
Study smarter with the SolutionInn App