1155. Rod Cutting Problem

EasyDynamic ProgrammingUnbounded KS

A rod of length n can be cut into integer-length pieces, where prices[i] is the price of a piece of length i+1. Return the maximum total price obtainable by cutting the rod (length equals the size of prices). The input is JSON {prices}.

Input: JSON {prices}.

Output: Integer — the maximum obtainable price.

Examples

Example 1
Input: {"prices":[1,5,8,9,10,17,17,20]}
Output: 22
Explanation: Cut into pieces of length 2 and 6.
Example 2
Input: {"prices":[2]}
Output: 2
Explanation: Length-1 rod.
Example 3
Input: {"prices":[3,5]}
Output: 6
Explanation: Two length-1 pieces beat one length-2.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →