Simple C++ solution
simple backtracking problem!!!\n\n1. mark the current column\'s 1\'s and reduce the number of cols you have and move onwards to other columns\n2. unmark the cur
simple backtracking problem!!!\n\n1. mark the current column\'s 1\'s and reduce the number of cols you have and move onwards to other columns\n2. unmark the current column\'s 1\'s and move onwards to other columns.\n3. base case is when you reach the end column or you don\'t have cols left to mark 1\'s.\n4. I later realised that you can flip steps 1 and 2 to make implementation easier but I am presenting the contest solution to you.\n```\nclass Solution {\npublic:\n    void backtrack(vector<vector<int>>& mat,int colno,int m,int n,int rem,int &res){\n        if(rem==0||colno==n){\n            int count = 0;\n            for(int i=0;i<m;i++){\n                bool flag = false;\n                for(int j=0;j<n;j++){\n                    if(mat[i][j]){\n                        flag = true;\n                        break;\n                    }\n                }\n                if(!flag)\n                    count++;\n            }\n            res = max(count,res);\n            return;\n        }\n        vector<bool> markedpos(m,false);\n        //choose this column and proceed\n        for(int i=0;i<m;i++){\n            if(mat[i][colno]==1){\n                mat[i][colno] = 0;\n                markedpos[i] = true;\n            }\n        }\n        backtrack(mat,colno+1,m,n,rem-1,res);\n        //undo \n        for(int i=0;i<m;i++){\n            if(markedpos[i]){\n                mat[i][colno] = 1;\n            }\n        }\n        backtrack(mat,colno+1,m,n,rem,res);\n    }\n    int maximumRows(vector<vector<int>>& mat, int cols) {\n        int res = 0;\n        int m = mat.size(),n = mat[0].size();\n        backtrack(mat,0,m,n,cols,res);\n        return res;\n    }\n};\n```\n\nPlease upvote if you found this helpful!
['Backtracking']