Skip to content

Commit 40a8e31

Browse files
authored
Merge pull request #893 from krishx06/feature/unbounded_knapsack
Unbounded Knapsack Problem
2 parents 4984050 + 854b74e commit 40a8e31

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
def getMaximumValue(weights, values, n, maxWeight):
2+
dp = [0] * (maxWeight + 1)
3+
4+
for w in range(1, maxWeight + 1):
5+
for i in range(n):
6+
if weights[i] <= w:
7+
dp[w] = max(dp[w], dp[w - weights[i]] + values[i])
8+
9+
return dp[maxWeight]

0 commit comments

Comments
 (0)