给出 n 个物品的体积 A[i] 及其价值 V[i],将他们装入一个大小为 m 的背包,最多能装入物品的总价值有多少?
参考代码:
class Solution: def backPack(sefl, m, A, V): f = [0 for i in range(m+1)] n = len(A) for i in range(n): for j in range(m, A[i]-1, -1): f[j] = max(f[j], f[j-A[i]] + V[i]) return f[m]