dp[i] = sum of dp[i-nums[j]] where nums[j] <= i.
1: class Solution {
2: public:
3: int combinationSum4(vector<int>& nums, int target) {
4: vector<int> res(target+1, 0);
5: dp[0] = 1;
6: for (int i = 1; i <= target; i++) {
7: for (int j = 0; j < nums.size(); j++) {
8: if (nums[j] <= i) dp[i] += dp[i-nums[j]];
9: }
10: }
11: return dp[target];
12: }
13: };
No comments:
Post a Comment