And so you could construct all subsets, check that the weight is less than the weight of the knapsack, and then choose the subset with the maximum value.
因此你可以构建所有子问题,判断它的重量,是否小于背包的重量,然后选择值最大的子问题。
Then if the weight of i is less than the available weight, I can return the value of i.
然后如果i的重量,小于剩下的重量,我将返回i的价值。
Fat has twice the calories per unit weight that protein or carbohydrate sugar has, as a consequence, has the greatest survival value.
单位重量中脂肪的热量含量,是蛋白质和碳水化合物的两倍,因此,脂肪才是最能维持生存的物质
And now we want to find the subset of a that has the maximum value, subject to the weight constraint.
会有一个值与其对应,现在我们想要找出满足,重量约束条件的a的最大值子集。
And so the value of with i will be the value of i plus whatever I can get using the remaining items and decrementing the weight by the weight of i.
所以装上i之后的总价值,就是i的价值加上剩下物品中,符合条件者的所有价值,再在剩余重量中减去i的重量。
应用推荐