206k views
1 vote
Modify the BotTOM-Up-CUT-RoD algorithm to return not only the value but the actual solution too. Consider a modification of the rod-cutting problem in which, in addition to a price pᵢ​ 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. Give a dynamic-programming algorithm to solve this modified problem.

User Anil Samal
by
9.1k points

1 Answer

2 votes

Final answer:

You can modify the Bottom-Up-Cut-Rod algorithm to return both the value and the actual solution. Here's a dynamic programming algorithm to solve this modified problem.

Step-by-step explanation:

The modified version of the Bottom-Up-Cut-Rod algorithm that returns both the value and the actual solution can be implemented using dynamic programming. Here is the algorithm:

  1. Create an array, let's call it 'revenue', to store the maximum revenue for each rod length.
  2. Create an array, let's call it 'solution', to store the actual solution for each rod length.
  3. Initialize revenue[0] = 0 and solution[0] = [].
  4. For each rod length 'i', starting from 1 to 'n', where 'n' is the total length of the rod:
  • Initialize revenue[i] = -Infinity and solution[i] = [].
  • For each cut length 'j', starting from 1 to 'i':
    • Calculate the revenue if a cut of length 'j' is made and the remaining rod length is 'i-j' using the formula: revenue[j] + price[i-j] - cost[j].
    • If this revenue is greater than revenue[i], update revenue[i] and solution[i] accordingly.

Finally, the maximum revenue can be found in revenue[n] and the actual solution can be found in solution[n].

User Jack Krupansky
by
8.4k points