You are viewing a single comment's thread. Return to all comments →
Javascript Dynamic Programming approach:
function unboundedKnapsack(k, arr) { let dp = Array(k+1).fill(0) for(let i=0; i <= k; i++) arr.forEach(e => dp[i] = Math.max(dp[i], e <= i ? dp[i-e]+e : 0)) return dp[k] }
Don't forget to fix the input read loop though.
Knapsack
You are viewing a single comment's thread. Return to all comments →
Javascript Dynamic Programming approach:
Don't forget to fix the input read loop though.