Function bottom_up_cut_rod(p, n) Dim r(n) As Integer Dim q As Integer r(0) = 0 For j = 1 To n q = -1 For i = 1 To j q = Math.Max(q, p(i) + r(j - i)) Next r(j) = q Next Return r(n) End Function