Rod Cutting
You are given a list of integers prices where prices[i] represents the price to sell a rod of size i + 1, and an integer n which represents the current size of the rod.
Given you can cut the rod into any number of different sizes, return the maximum profit that can be earned.
Constraints
- m = n ≤ 1000where- mis the length of- prices.
https://binarysearch.com/problems/Rod-Cutting
Examples
Example 1
Input
- prices = [1, 3, 5, 7, 7, 7]
- n = 6
Output
- answer = 10
Explanation
The price table shows that we can
- Sell a rod of size 1for price of1
- Sell a rod of size 2for price of3
- Sell a rod of size 3for price of5
- Sell a rod of size 4for price of7
- Sell a rod of size 5for price of7
- Sell a rod of size 6for price of7
The optimal way to cut the rod is to split it into 2 pieces of length 3, to achieve profit of 10.
 
       
      
Leave a comment