From 4e7637556b14e6600a73928269d324bc227e08ab Mon Sep 17 00:00:00 2001 From: a12bb <2713204748@qq.com> Date: Thu, 7 Mar 2024 20:13:39 +0800 Subject: [PATCH] =?UTF-8?q?Update=200518.=E9=9B=B6=E9=92=B1=E5=85=91?= =?UTF-8?q?=E6=8D=A2II.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 0518.零钱兑换II新增C语言实现 --- problems/0518.零钱兑换II.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/problems/0518.零钱兑换II.md b/problems/0518.零钱兑换II.md index da1c4755..59fdf6cd 100644 --- a/problems/0518.零钱兑换II.md +++ b/problems/0518.零钱兑换II.md @@ -353,7 +353,28 @@ object Solution { } } ``` +## C + +```c +int change(int amount, int* coins, int coinsSize) { + int dp[amount + 1]; + memset(dp, 0, sizeof (dp)); + dp[0] = 1; + // 遍历物品 + for(int i = 0; i < coinsSize; i++){ + // 遍历背包 + for(int j = coins[i]; j <= amount; j++){ + dp[j] += dp[j - coins[i]]; + } + } + return dp[amount]; +} +``` + + + ### C# + ```csharp public class Solution { @@ -378,3 +399,4 @@ public class Solution +