0% found this document useful (0 votes)
48 views1 page

R (I) : The Optimal Revenue While Cutting A Length I Rod

The document describes the rod cutting problem, where given a rod of length n, the goal is to cut it into pieces that maximize total revenue based on prices for different piece lengths. It defines the optimal substructure as r[i], the optimal revenue for cutting a rod of length i. The base case is r[1] = p1, where p1 is the price of a length 1 rod. The recurrence is to try all possible cuts and take the maximum revenue of cutting or not cutting. It provides a table to fill out to calculate r[i] and prev[i], where prev[i] stores the optimal cut for rod length i. Finally, it asks to write the dynamic programming code to compute r

Uploaded by

FaheemMasood
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views1 page

R (I) : The Optimal Revenue While Cutting A Length I Rod

The document describes the rod cutting problem, where given a rod of length n, the goal is to cut it into pieces that maximize total revenue based on prices for different piece lengths. It defines the optimal substructure as r[i], the optimal revenue for cutting a rod of length i. The base case is r[1] = p1, where p1 is the price of a length 1 rod. The recurrence is to try all possible cuts and take the maximum revenue of cutting or not cutting. It provides a table to fill out to calculate r[i] and prev[i], where prev[i] stores the optimal cut for rod length i. Finally, it asks to write the dynamic programming code to compute r

Uploaded by

FaheemMasood
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Dynamic

Programming Class-work

The Rod Cutting Problem

We have a rod of length n units. We wish to cut it up into pieces and sell them. For
example, if n=5, we could cut the rod like 1+1+1+1+1, or 2+2+1, or 3+2, or 3+1+1,
4+1, 5, etc. However, each piece-length has a different price. Therefore, the total
revenue generated by a cutting may be different from the total revenue generated by
a different cutting. For example, look at the table below. In this case n=10. If we cut
the rod as 5+5 we get a revenue of 270; if we cut it as 9+1, we get a revenue of 230; if
we sell the entire length 10 piece we get a revenue of 235 etc. The prices for all
piece-lengths are given to us in input. We wish to Pind a cutting that maximises the
total revenue.

An optimal sub-structure for the rod cutting problem may be dePined as follows.

r[i] := the optimal revenue while cutting a length i rod.

(i) What is the base case, r[1] = ?

(ii) What is the recurrence for r[i]?

(iii) Fill the following table using r[i], as dePined above.

i 1 2 3 4 5 6 7 8 9 10

p 10 50 80 100 135 155 180 190 220 235

r
prev[i]

(iii) What do you store in prev[i], the optimal cut for a rod of length i?

(iv) Write the bottom-up DP code to compute r[i] and c[i]. Add the code that uses
r and c to return the optimal revenue and corresponding cutting.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy