Leetcode 377. Combination Sum Ⅳ (DAY 46) ---- Dynamic programming learning period (Sooner or later when the pigeon goes down, it will become sfw, and it will not waste time to do problems every day)

Original title

Insert picture description here



Code implementation (first brush small part to see the solution and most of the self-solving)

int combinationSum4(int* nums, int numsSize, int target){
    
    
    unsigned long* dp = (unsigned long*)malloc(sizeof(unsigned long) * (target+1));
    int i,j;
    memset(dp,0,sizeof(unsigned long) * (target+1));
    dp[0] = 1;
    for(i=1;i<=target;i++)
    {
    
    
        for(j=0;j<numsSize;j++)
        {
    
    
            if(i >= nums[j])
                dp[i] += dp[i-nums[j]];
        }
    }
    return dp[target];
}

Guess you like

Origin blog.csdn.net/qq_37500516/article/details/113823408