快開學了...我還能撐到30天嗎><
使用dp就不要想著一步登天,要從頭就紀錄方法數到尾(ps:dp到現在還是不大會用......)
ref:https://leetcode.com/problems/combination-sum-iv/solutions/4020273/easy-c-recursive-iterative-dp-beats-100-with-debug-info/?envType=daily-question&envId=2023-09-09
class Solution {
public:
int combinationSum4(vector<int>& nums, int target) {
vector<unsigned> dp(target + 1, 0);
dp[0] = 1;
for(int i = 1; i <= target; i++){
for(int x : nums){
if(i >= x){
dp[i] += dp[i - x];
}
}
}
return dp[target];
}
};