C++ Solution | Easy to Understand | Using Backtracking
In this problem we apply concept of recursion of take and non take because of small constraint.\nSteps\n1. first we make a recursive function \'fun\' in which w
In this problem we apply concept of recursion of take and non take because of small constraint.\n**Steps**\n**1.** first we make a recursive function \'fun\' in which we pass current index, given matrix, given cols and visited array.\n**2.** So visited array take care of column of matrix that which column is selected or which is not.\n**3.** So mainly in recursive function, we try out all possible column which are possible for given cols value. we will do this with the help of take and non take method. and we update our visited array for that column which is taken.\n**4.** For Base case, if our cols value become 0 or if we cover all column means now we check for covered row.\n**5.** So Now we traverse our matrix and check if that column is unvisited and value of that mat[row][col]==1 means that row is not a covered row so we come out of loop of column.\n**6.** otherwise we update the value of covered row by 1 (count++).\n**7.** At last we take maximum of count and ans. because we have to calculate maximum row covered.\n\n**Code**\n\t\t\n\t\tclass Solution {\n\t\t\tpublic:\n\t\t\t\tint m,n;\n\t\t\t\tint ans=INT_MIN;\n\t\t\t\tvoid fun(int i,vector<vector<int>> &mat,int col,vector<int> vis){\n\t\t\t\t\tint count=0;\n\t\t\t\t\tif(col==0 || i==n){\n\n\t\t\t\t\t\tfor(int p=0;p<m;p++){\n\t\t\t\t\t\t\tint f=0;\n\t\t\t\t\t\t\tfor(int q=0;q<n;q++){\n\t\t\t\t\t\t\t\tif(mat[p][q]==1 && vis[q]==0){\n\t\t\t\t\t\t\t\t\tf=1;\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif(f==0) count++;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tans=max(ans,count);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tfun(i+1,mat,col,vis);\n\t\t\t\t\tvis[i]=1;\n\t\t\t\t\tcol--;\n\t\t\t\t\tfun(i+1,mat,col,vis);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tint maximumRows(vector<vector<int>>& mat, int cols) {\n\t\t\t\t\tm=mat.size();\n\t\t\t\t\tn=mat[0].size();\n\t\t\t\t\tvector<int> vis(n,0);\n\t\t\t\t\tfun(0,mat,cols,vis);\n\t\t\t\t\treturn ans;\n\t\t\t\t}\n\t\t\t};\n\t\t\t\n**Please upvote if you like the explanation **
['Backtracking', 'Recursion', 'C']