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 — JavaScript/Dynamic-Programming/RodCutting.js at master · Sese-Brazil/JavaScript Expand file tree/ Copy pathRodCutting.jsMore file actions 19 lines (16 loc) · 490 Bytes / Copy pathRodCutting.jsFile metadata and controls19 lines (16 loc) · 490 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 /* * You are given a rod of 'n' length and an array of prices associated with all the lengths less than 'n'. * Find the maximum profit possible by cutting the rod and selling the pieces. */ export function rodCut(prices, n) { const memo = new Array(n + 1) memo[0] = 0 for (let i = 1; i <= n; i++) { let maxVal = Number.MIN_VALUE for (let j = 0; j < i; j++) { maxVal = Math.max(maxVal, prices[j] + memo[i - j - 1]) } memo[i] = maxVal } return memo[n] } |
| You are visitor 01402520 — 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. |