0% found this document useful (0 votes)
11 views13 pages

RodCutting DP

The rod cutting problem involves maximizing profit by cutting a steel rod of length n into shorter pieces, each with a specified price. The solution utilizes dynamic programming to identify subproblems, develop a recurrence relation, and compute optimal prices for each length. An example illustrates the process, showing how to achieve maximum revenue through strategic cuts.

Uploaded by

ma23btech11005
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)
11 views13 pages

RodCutting DP

The rod cutting problem involves maximizing profit by cutting a steel rod of length n into shorter pieces, each with a specified price. The solution utilizes dynamic programming to identify subproblems, develop a recurrence relation, and compute optimal prices for each length. An example illustrates the process, showing how to achieve maximum revenue through strategic cuts.

Uploaded by

ma23btech11005
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/ 13

The rod cutting problem

Sterling Enterprises buys long steel rods and


cuts them into shorter rods to sell.

Different prices for different lengths


The rod cutting problem

Length 1 2 3 4 5 6 7 8 9 10
Price 1 5 8 9 10 17 17 20 24 30

Given a rod of length n, how to break it and sell for maximum price?
The rod cutting problem

Length 1 2 3 4 5 6 7 8 9 10
Price 1 5 8 9 10 17 17 20 24 30

Eg: n=8

No cut: 20
1+7:18
2+3+3: 21
Optima: 2+6: 22
Rod Cutting

Problem:
Input: n and P(1), P(2), …, P(n)
P(i): price of selling a piece of length i
Output:
(n1,n2,…,nk): n1+n2+ … +nk = n
And P(n1)+P(n2)+…+P(nk) is maximized.
Dynamic Programming
Step 1: Identify subproblems to be solved.

Step 2: Develop a recurrence relation for each subproblem.

Step 3: Solve subproblems in bottom-up/tabular computation.

Step 4: Traceback to get solution.


Step 1: Subproblems

For i=1 to n:
R(i)=Maximum price that can be obtained by breaking
and selling a piece of length i.
Step 2: Recurrence

R(n) = Max(P(n), Max{P(i)+R(n-i): 1<=i<=n-1})


Step 3: Compute values for subproblems bottom-up

Initialize R(i)=P(i) for all i


For i= 2 to n
For j=1 to i-1
value=P(j)+R(j-i)
if (value>R(i))
R(i)=value
Step 3: Compute values for subproblems bottom-up

Initialize R(i)=P(i) for all i, J(i)=i for all i.


For i= 2 to n
For j=1 to i-1
value=P(j)+R(j-i)
if (value>R(i))
R(i)=value
J(i)=j
Step 4: Traceback: Compute the solution

Set i=n
While (J(i)<i) do:
print(J(i))
Set i=i-J(i)
Print i
Example run for n=10:

i 1 2 3 4 5 6 7 8 9 10
P(i) 1 5 8 9 10 17 17 20 24 30
R(i) 1 5 8 10 13 17 18 22 25 30
J(i) 1 2 3 1 2 6 1 2 3 10
Example for n=15:

If n=15 and P(11)=P(12)=P(13)=P(14)=P(15)=0, then


we get J(15)=2, J(13)=3, J(10)=10, so that the optimal
division for 15 is 15=2+3+10, with a price of 43.

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