class Solution {
public:
int combinationSum4(vector<int>& nums, int target) {
vector<int> sortedNums(nums);
sort(sortedNums.begin(), sortedNums.end());
vector<int> results(target + 1, 0);
results[0] = 1;
for (int i = 1; i <= target; i++) {
for (int j = 0; j < sortedNums.size() && sortedNums[j] <= i; j++) {
results[i] += results[i  sortedNums[j]];
}
}
return results[target];
}
};
3ms c++ DP


neat solution, but you can add a judgement to make it faster.
'''
int combinationSum4(vector<int>& nums, int target) {
sort(nums.begin(), nums.end());
vector<int> res(target+1, 0);
res[0] = 1;
for(int i = 0; i < target+1; ++i){
for(int j = 0; j < nums.size(); ++j){
if(i >= nums[j]){
res[i] += res[inums[j]];
}
else{
break;
}
}
}
return res[target];
}
'''