<p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>

<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>&#39;s and </em><code>n</code><em> </em><code>1</code><em>&#39;s in the subset</em>.</p>

<p>A set <code>x</code> is a <strong>subset</strong> of a set <code>y</code> if all elements of <code>x</code> are also elements of <code>y</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> strs = [&quot;10&quot;,&quot;0001&quot;,&quot;111001&quot;,&quot;1&quot;,&quot;0&quot;], m = 5, n = 3
<strong>Output:</strong> 4
<strong>Explanation:</strong> The largest subset with at most 5 0&#39;s and 3 1&#39;s is {&quot;10&quot;, &quot;0001&quot;, &quot;1&quot;, &quot;0&quot;}, so the answer is 4.
Other valid but smaller subsets include {&quot;0001&quot;, &quot;1&quot;} and {&quot;10&quot;, &quot;1&quot;, &quot;0&quot;}.
{&quot;111001&quot;} is an invalid subset because it contains 4 1&#39;s, greater than the maximum of 3.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> strs = [&quot;10&quot;,&quot;0&quot;,&quot;1&quot;], m = 1, n = 1
<strong>Output:</strong> 2
<b>Explanation:</b> The largest subset is {&quot;0&quot;, &quot;1&quot;}, so the answer is 2.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= strs.length &lt;= 600</code></li>
	<li><code>1 &lt;= strs[i].length &lt;= 100</code></li>
	<li><code>strs[i]</code> consists only of digits <code>&#39;0&#39;</code> and <code>&#39;1&#39;</code>.</li>
	<li><code>1 &lt;= m, n &lt;= 100</code></li>
</ul>

class Solution {
public:
     int dp[700][101][101];
      vector<string>v;
     int solve(int curr,vector<string>&strs,int m,int n){
           if(curr<0||(m<=0&&n<=0)){
             return 0;
           }
           
           if(dp[curr][m][n]!=0){
            return dp[curr][m][n];
           }
           string a=strs[curr];
           int cnt0=0;
           int cnt1=0;
           for(char c:a){
            if(c=='1'){cnt1++;}
            else cnt0++;
           }

           if(cnt1<=n&&cnt0<=m){
               return dp[curr][m][n]=max(1+solve(curr-1,strs,m-cnt0,n-cnt1),solve(curr-1,strs,m,n));
           }

            dp[curr][m][n]=solve(curr-1,strs,m,n);
           return dp[curr][m][n];

     }
//      int rec(int k,int m,int n){
//     if(k<=0||(m<=0&&n<=0))return 0;//Base Condition.
//     if(t[k][m][n]) return t[k][m][n];
//     string s=v[k-1];
//     int cnt0=0,cnt1=0;//count of 0s and 1s in string.
//     for(auto i:s){
//         if(i=='0')cnt0++;
//         else cnt1++;
//     }
//     if(cnt0>m||cnt1>n) return t[k][m][n]=rec(k-1,m,n);//recursion call if one or both the parameters are small.
//     return t[k][m][n]=max(rec(k-1,m,n),1+rec(k-1,m-cnt0,n-cnt1));//recursion call for finding maximum count.
// }
    int findMaxForm(vector<string>& strs, int m, int n) {
        //   for(int i=0;i<700;i++){
        //     for(int j=0;j<700;j++){
        //        for(int k=0;k<700;k++) 
        //           dp[i][j][k]=0;
        //     }
        //   }
    //    v=strs;
    // return rec(v.size(),m,n);

      return solve(strs.size()-1,strs,m,n);
    }
};
45220