MCPcopy Create free account
hub / github.com/Aaaaaaaty/blog / calMax

Function calMax

Algorithm/dynamicProgramming/test.js:4–12  ·  view source on GitHub ↗
(price, n, num)

Source from the content-addressed store, hash-verified

2var price = [1,2,7,9,10,12,13,20,24,30,30]
3var num = 0
4function calMax(price, n, num) {
5 num++
6 if(!n) return 0
7 var q = 0
8 for(var i = 1; i<=n; i++) {
9 q = Math.max(q, price[i - 1] + calMax(price, n - i, num))
10 }
11 return q
12}
13var result = calMax(price, length, num)
14console.log(result)

Callers 1

test.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected