Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.40 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.        
  12.         // if no cuts are made we can just return this value.
  13.         q = p[j]
  14.  
  15.         for i = 1 to j - 1
  16.         {
  17.             // adjust for the fixed cost of making a cut
  18.             q = max(q, p[i] + arr[j-i] - c)
  19.         }
  20.  
  21.         r[j] = q
  22.     }
  23.     // return the total revenue
  24.     return r[n]
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement