JAVA | BACKTRACK | RECURSION | Runtime 1ms | 100% faster
This question is similar to 698. Partition to K Equal Sum Subsets.\nWe try all possible combinations of columns, once we select the given number of columns, we 
This question is similar to [698. Partition to K Equal Sum Subsets](https://leetcode.com/problems/partition-to-k-equal-sum-subsets/).\nWe try all possible combinations of columns, once we select the given number of columns, we check that for how many rows in the matrix, the below condition is true:-\n1. Each cell of the row is \'0\', or\n2. If the cell of the row is \'1\', then the cell\'s column value(say, \'j\') should be \'1\'(i.e. this column is selected by us) in the \'s\' array. (s[j]==1).\n\nWe return the count of the rows.\nIn order to get our answer we maintain the maximum value(max number of rows that could be selected) in \'ans\'.\n```\nclass Solution {\n    public int maximumRows(int[][] mat, int cols) {\n        \n        int m=mat.length;\n        int n=mat[0].length;\n        \n        int[] s=new int[n];\n        \n        return f(0,m,n,cols,mat,s);\n    }\n    \n    public int f(int ind,int m,int n,int cols,int[][] mat,int[] s){\n        \n        if(cols==0){\n            int count=0;\n            for(int i=0; i<m; i++){\n\t\t\t//supposing that this row is valid\n                boolean selected=true;\n                for(int j=0; j<n; j++){\n\t\t\t\t//if any cell of this row violates the given two conditions, then the row is discarded\n                    if(mat[i][j]==1 && s[j]!=1)\n                        selected=false;\n                }\n                if(selected)\n                    count+=1;\n            }\n            \n            return count;\n        }\n        \n        int ans=-1;\n        for(int i=ind; i<n; i++){\n            \n            s[i]=1; //do\n            ans=Math.max(ans,f(i+1,m,n,cols-1,mat,s));\n            s[i]=0; //undo / backtrack\n        }\n        \n        return ans;\n    }\n}\n```
['Backtracking', 'Recursion', 'Java']