leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0474.cpp (554B)


      1 class Solution {
      2   public:
      3     int findMaxForm(const vector<string> &strs, int m, int n) const {
      4         static int dp[101][101];
      5 
      6         memset(dp, 0x00, sizeof(dp));
      7         for (const auto &s : strs) {
      8             const int zero = count(begin(s), end(s), '0');
      9             const int one = size(s) - zero;
     10             for (int i = m; i >= zero; i--) {
     11                 for (int j = n; j >= one; j--) {
     12                     dp[i][j] = max(dp[i][j], 1 + dp[i - zero][j - one]);
     13                 }
     14             }
     15         }
     16 
     17         return dp[m][n];
     18     }
     19 };