nums
,和一个目标整数 target
。请你从 nums
中找出并返回总和为 target
的元素组合的个数。int combinationSum4(int* nums, int numsSize, int target) { int dp[1005], i, j; memset(dp, 0, sizeof(dp)); dp[0] = 1; for (i = 1; i <= target; i++) { for (j = 0; j < numsSize; j++) { if (nums[j] <= i && dp[i - nums[j]] < INT_MAX - dp[i]) { dp[i] += dp[i - nums[j]]; } } } return dp[target]; }
原文:https://www.cnblogs.com/rongrongrong/p/14697744.html