Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.38 KB | None | 0 0
  1. Mod_rod_cut(p, n, c)
  2. {
  3.     // Create a new array.
  4.     arr[0..n]
  5.    
  6.     // first element in the new array is empty.
  7.     arr[0] = 0
  8.    
  9.     for j = 1 to n
  10.        
  11.         // if no cuts are made we can just return this value.
  12.         q = p[j]
  13.  
  14.         for i = 1 to j - 1
  15.             // adjust for the fixed cost of making a cut
  16.             q = max(q, p[i] + arr[j-i] - c)
  17.        
  18.         r[j] = q
  19.    
  20.     // return the total revenue
  21.     return r[n]
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement