We can define a function K(W, n) that represents the maximum value that can be obtained by selecting items from 1 to n, considering the weight constraint.
The recursive formula is as follows:
K(W, n) = 0, if W = 0 or n = 0 (base case)
K(W, n) = K(W, n-1), if
Show more…