From 6bae30472cf1e0380c3a6652b877ff7777d3f993 Mon Sep 17 00:00:00 2001 From: a12bb <2713204748@qq.com> Date: Fri, 8 Mar 2024 22:42:26 +0800 Subject: [PATCH] =?UTF-8?q?Update=200377.=E7=BB=84=E5=90=88=E6=80=BB?= =?UTF-8?q?=E5=92=8C=E2=85=A3.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增C语言实现 --- problems/0377.组合总和Ⅳ.md | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/problems/0377.组合总和Ⅳ.md b/problems/0377.组合总和Ⅳ.md index a840ec9b..6f81bffe 100644 --- a/problems/0377.组合总和Ⅳ.md +++ b/problems/0377.组合总和Ⅳ.md @@ -312,7 +312,28 @@ impl Solution { } } ``` +### C + +```c +int combinationSum4(int* nums, int numsSize, int target) { + int dp[target + 1]; + memset(dp, 0, sizeof (dp )); + dp[0] = 1; + for(int i = 0; i <= target; i++){ + for(int j = 0; j < numsSize; j++){ + if(i - nums[j] >= 0 && dp[i] < INT_MAX - dp[i - nums[j]]){ + dp[i] += dp[i - nums[j]]; + } + } + } + return dp[target]; +} +``` + + + ### C# + ```csharp public class Solution { @@ -340,4 +361,3 @@ public class Solution -