https://programmercarl.com/背包理论基础01背包-1.html#总结
https://www.bilibili.com/video/BV1C7411K79w?p=1&vd_source=46d50b5d646b50dcb2a208d3946b1598
package dynamic;
public class Beibao {
public static void main(String[] args) {
int[] weight = {1,3,4};
int[] value = {15,20,30};
int bagSize = 4;
testWeightBagProblem(weight,value,bagSize);
}
private static void testWeightBagProblem(int[] weight, int[] value, int bagSize) {
int[][] dp = new int[weight.length+1][bagSize+1];
for (int i = 1; i <= weight.length; i++) {
for (int j = 1; j <= bagSize; j++) {
if(j<weight[i-1]){
dp[i][j] = dp[i-1][j];
}else {
dp[i][j] = Math.max(dp[i-1][j],dp[i-1][j-weight[i-1]]+value[i-1]);
}
}
}
}
}
标签:背包,weight,testWeightBagProblem,int,完全,value,&&,bagSize
From: https://www.cnblogs.com/chenyi502/p/17728874.html