From 0a30cd7a2664cc8198635bf0c69447abe3c57fa4 Mon Sep 17 00:00:00 2001 From: a12bb <2713204748@qq.com> Date: Thu, 7 Mar 2024 20:04:45 +0800 Subject: [PATCH] =?UTF-8?q?Update=200474.=E4=B8=80=E5=92=8C=E9=9B=B6.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 0474.一和零新增C语言实现 --- problems/0474.一和零.md | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/problems/0474.一和零.md b/problems/0474.一和零.md index 904d941e..7e04ae1e 100644 --- a/problems/0474.一和零.md +++ b/problems/0474.一和零.md @@ -533,7 +533,39 @@ impl Solution { } } ``` +```c +#define max(a, b) ((a) > (b) ? (a) : (b)) + +int findMaxForm(char** strs, int strsSize, int m, int n) { + int dp[m + 1][n + 1]; + memset(dp, 0, sizeof (int ) * (m + 1) * (n + 1)); + for(int i = 0; i < strsSize; i++){ + // 统计0和1的数量 + int count0 = 0; + int count1 = 0; + char *str = strs[i]; + while (*str != '\0'){ + if(*str == '0'){ + count0++; + } else{ + count1++; + } + str++; + } + for(int j = m; j >= count0; j--){ + for(int k = n; k >= count1; k--){ + dp[j][k] = max(dp[j][k], dp[j - count0][k - count1] + 1); + } + } + } + return dp[m][n]; +} +``` + + + ### C# + ```csharp public class Solution { @@ -565,4 +597,3 @@ public class Solution -