474. 一和零
作者:互联网
class Solution {
public:
int findMaxForm(vector<string>& strs, int m, int n) {
int cnt0, cnt1;
vector<vector<int> >dp(m+1,vector<int>(n+1,0));
for(string s: strs)
{
cnt0=0,cnt1=0;
for(char c: s)
{
if(c=='0')
cnt0++;
else
cnt1++;
}
for(int i=m; i>=cnt0; i--)
for(int j=n; j>=cnt1; j--)
{
dp[i][j]=max(dp[i][j], dp[i-cnt0][j-cnt1]+1);
}
}
return dp[m][n];
}
};
标签:474,int,++,vector,cnt1,cnt0,dp 来源: https://blog.csdn.net/Scarlett_Guan/article/details/99186749