Given a rod of length n and a table of prices price[i] for rod lengths i = 1, 2, ..., n, determine the maximum revenue obtainable by cutting up the rod and selling the pieces.
- An integer
n(length of the rod). - An array
priceof lengthn.
Input: n = 8, price = [1, 5, 8, 9, 10, 17, 17, 20]
Output: 22
Explanation: Cut the rod into pieces of length 2 and 6 (revenue = 5 + 17 = 22).