Brute force using Backtracking | C++
I tried generating all possible combination of numSelect columns using the f( ) function using backtracking. Then just iteraterd over the matrix for each combin
I tried generating all possible combination of **numSelect** columns using the `f( )` function using backtracking. Then just iteraterd over the matrix for each combination of columns, checked the given condition which just says that if the cell is equal to 1 then it has to be a part of the column selected by current combination of columns.\n\n```\nclass Solution\n{\n    int rows, cols;\n\n    void f(int idx, int numSelect, vector<vector<int>> &combs, vector<int> cur)\n    {\n        if (numSelect <= 0 or idx>=cols)\n        {\n            if(numSelect<=0)\n                combs.push_back(cur);\n            return;\n        }\n        for (int i = idx; i < cols; i++)\n        {\n            cur.push_back(i);\n            f(i+1, numSelect - 1, combs, cur);\n            cur.pop_back();\n            f(i+1, numSelect, combs, cur);\n        }\n    }\n\n    int help(vector<vector<int>> &matrix, int numSelect)\n    {\n        vector<vector<int>> combs;\n        vector<int> cur;\n        f(0, numSelect, combs, cur);\n        int maxi= 0;\n        for (auto &v : combs)\n        {\n            int cnt = 0;\n            for (int j = 0; j < rows; j++)\n            {\n                bool is=true;\n                for (int k = 0; k < cols; k++)\n                {\n                    if(find(v.begin(), v.end(), k) == v.end() and matrix[j][k]==1){\n                        is =false;\n                        break;\n                    }\n                }\n                if(is)\n                {\n                    cnt++;\n                }\n            }\n            maxi=max(maxi,cnt);\n        }\n        return maxi;\n    }\n\npublic:\n    int maximumRows(vector<vector<int>> &matrix, int numSelect)\n    {\n        rows = matrix.size(), cols = matrix[0].size();\n        return help(matrix, numSelect);\n    }\n};\n\n```
['C++']