Backpack V
Problem 单次选择+装满可能性总数
Example
[7]
[1, 3, 3]
return 2Solution
public class Solution {
public int backPackV(int[] nums, int target) {
int[] dp = new int[target+1];
dp[0] = 1;
for (int i = 0; i < nums.length; i++) {
for (int j = target; j >= 0; j--) {
if (j >= nums[i]) dp[j] += dp[j-nums[i]];
}
}
return dp[target];
}
}Last updated
Was this helpful?