InferenceAI

Enter at least two characters to search.

Start free

Rod Cutting

mediumDynamic Programming25 min25 XP

A piece of length i+1i + 1 sells for prices[i]. Return the maximum revenue from cutting a rod of length len(prices) into pieces (or not cutting it).

Examples

EXAMPLE WALKTHROUGHclassic

A guided view of the published example, not a trace of your code.

INPUT[[1,5,8,9,10,17,17,20]]
TASKrod_cutting_value()
EXPECTED OUTPUT22

Start with the input values shown in this example.

Example 1 of 3

Input: prices = [1,5,8,9,10,17,17,20]

Output: 22

Explanation: classic

Input: prices = [3,5,8,9,10,17,17,20]

Output: 24

Explanation: many small cuts

Input: prices = [2]

Output: 2

Explanation: length one

Hint 1

best[L] = max over the first cut size c of prices[c - 1] + best[L - c].

Topics

DSADynamic ProgrammingPython