Consider a modification of the rodcutting problem in which i

Consider a modification of the rod-cutting problem in which, in addition to a price pi for each rod, each cut incurs a fixed cost of c. The revenue associated with a solution is now the sum of the prices of the pieces minus the costs of making the cuts. Suppose we also had limit l_i on the maximum number of pieces of length i we are allowed to produce, for  i=1,2,...,n. Write a dynamic program for this modified problem.

Solution

MODIFIEDCUTROD

( p , n , c )

give r [ 0 . . n ] be a brand new a r r a y

r [ zero ] = zero

f o r j = one t o n

q = p [ j ]

f o r i= one t o j 1

q = max( q , p [ i ]+ r [ ji ]c )

r [ j ] = letter of the alphabet

r e t u r n r [ n ]

The major modification needed is within the body of the inner for loop, that currently reads letter of the alphabet = max(q, p[i] + r[j i] c). this modification reflects the fixed charge of constructing the cut, that is subtracted from the revenue. we tend to even have to handle the case within which we tend to build no cuts (when i equals j); the overall revenue during this case is solely p[j]. Thus, we tend to modify the inner for loop to run from i to j one rather than to j. The assignment letter of the alphabet = p[j] takes care of the case of no cuts. If we tend to didn\'t build these modifications, then even within the case of no cuts, we might be deducting c from the overall revenue

Consider a modification of the rod-cutting problem in which, in addition to a price pi for each rod, each cut incurs a fixed cost of c. The revenue associated w

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site