Rod Cutting — Filling the DP Array

dp[len] = max over first cut c of ( price[c] + dp[len − c] ). Watch each length try every first cut, keep the max, record the choice, then reconstruct the pieces on a rod.

step 0

Price table & dp[] array

dp[len] = best revenue for a rod of length len
choice[len] = first cut that achieved dp[len]
length being filled dependency dp[len−c]

Trying each first cut c

For length len, try c = 1..len: candidate = price[c] + dp[len − c]. Keep the maximum.

Reconstructed cut on the rod

Press Step to begin. We fill dp[0], dp[1], …, dp[n] in order; each length tries every first cut and keeps the best.
Self-contained visualization. Exact integer revenue (no modulus needed at these sizes). The reconstruction follows choice[] backward: len → len − choice[len] until 0. See junior.md and professional.md for the optimal-substructure proof that the best plan for len is the best first cut plus the best plan for the remainder.