~/ learn/ comp-372/ cards/ The DP method & rod cutting
1 of 5

CLRS BOTTOM-UP-CUT-ROD (type it)

CLRS BOTTOM-UP-CUT-ROD (type it)

Answer

BOTTOM-UP-CUT-ROD(p, n) let r[0..n] be new array r[0] = 0 for j = 1 to n q = -∞ for i = 1 to j q = max(q, p[i] + r[j - i]) r[j] = q return r[n]

The outer loop fixes the rod length j; the inner loop tries every first-cut i and reuses the already-computed r[j-i]. Doubly nested → Θ(n²).

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/0f68ef17-ec20-42df-8554-d78c2a757f27/flashcard utf-8 LF