Facebook
From Crimson Flamingo, 5 Months ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 69
  1. Function bottom_up_cut_rod(p, n)
  2.         Dim r(n) As Integer
  3.         Dim q As Integer
  4.         r(0) = 0
  5.         For j = 1 To n
  6.             q = -1
  7.             For i = 1 To j
  8.                 q = Math.Max(q, p(i) + r(j - i))
  9.             Next
  10.             r(j) = q
  11.         Next
  12.         Return r(n)
  13.     End Function