双重背包裸题
class Solution {
public:
int findMaxForm(vector<string>& strs, int m, int n) {
int dp[m+2][n+2];
memset(dp,0,sizeof(dp));
for(auto s:strs)
{
pair tmp=get(s);
for(int i=m;i>=tmp.second;i--)
{
for(int j=n;j>=tmp.first;j--)
{
dp[i][j]=max(dp[i][j],dp[i-tmp.second][j-tmp.first]+1);
}
}
}
return dp[m][n];
}
pair<int,int> get(string s)
{
int one=0;
int zero=0;
for(auto t:s)
{
if(t=='0') zero++;
else one++;
}
return make_pair(one,zero);
}
};