-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path474.cpp
More file actions
22 lines (22 loc) · 686 Bytes
/
474.cpp
File metadata and controls
22 lines (22 loc) · 686 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class Solution {
public:
int findMaxForm(vector<string>& strs, int m, int n) {
vector<vector<int>> dp(m + 1, vector<int>(n + 1, 0));
int res = 0;
for (auto str : strs) {
int zeroCount = 0;
int oneCount = 0;
for (auto c : str) {
if (c == '0') zeroCount++;
else oneCount++;
}
for (int i = m; i >= zeroCount; --i) {
for (int j = n; j >= oneCount; --j) {
dp[i][j] = max(dp[i][j], dp[i - zeroCount][j - oneCount] + 1);
res = max(res, dp[i][j]);
}
}
}
return res;
}
};