GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — algorithms/dp/rod_cut.py at master · deba999/algorithms Expand file tree/ Copy pathrod_cut.pyMore file actions 26 lines (19 loc) · 703 Bytes / Copy pathrod_cut.pyFile metadata and controls26 lines (19 loc) · 703 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 # A Dynamic Programming solution for Rod cutting problem INT_MIN = -32767 # Returns the best obtainable price for a rod of length n and # price[] as prices of different pieces def cutRod(price): n = len(price) val = [0] * (n + 1) # Build the table val[] in bottom up manner and return # the last entry from the table for i in range(1, n + 1): max_val = INT_MIN for j in range(i): max_val = max(max_val, price[j] + val[i - j - 1]) val[i] = max_val return val[n] # Driver program to test above functions arr = [1, 5, 8, 9, 10, 17, 17, 20] print("Maximum Obtainable Value is " + str(cutRod(arr))) # This code is contributed by Bhavya Jain |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |