Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

READ INSTRUCTIONS CAREFULLY AND CODE IN C++ Rod Cutting Description In this assignment you are asked to implement a dynamic programming algorithm for the Rod

READ INSTRUCTIONS CAREFULLY AND CODE IN C++

Rod Cutting Description In this assignment you are asked to implement a dynamic programming algorithm for the Rod Cutting Problem (chapter 15.1). In the Rod Cutting problem, you are given an integer n 1, along with a sequence of positive prices, p1, p2, ..., pn, where pi is the market price of 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, p1, p2, ..., pn 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, and output -1, followed by a space key; separate two adjacent numbers by a space key. Examples of input and output Input 7 1 5 8 9 10 17 17 Output 18 1 6 -1 Alternatively, the second line can be replaced with 6 1 -1, 2 2 3 -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 be correct.

READ INSTRUCTIONS CAREFULLY AND CODE IN C++

image text in transcribed

READ INSTRUCTIONS CAREFULLY AND CODE IN C++

Rod Cutting Description In this assignment you are asked to implement a dynamic programming algorithm for the Rod Cutting Problem (chapter 15.1). In the Rod Cutting problem, you are given an integer n 2 1, along with a sequence of positive prices, pi, P2, ..., Pn, where p is the market price of 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 pi, p2., Pn are all integers. Input The input has the following format. The input starts with n. Then, p1, P2 one per each line Pn follow 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, and output -1, followed by a space key; separate two adjacent numbers by a space key Examples of input and output Input 7 8 10 17 17 Output 18 1 6-1 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 be correct

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M. Kroenke, David J. Auer

7th edition

133544621, 133544626, 0-13-354462-1, 978-0133544626

More Books

Students also viewed these Databases questions