Easy to follow c++ code
Intuition\n\nFinding all combination of the columns (question 77) and check the maximum covered rows by each of them and return the maximum.\n\n\n# Approach\n\n
# Intuition\n\nFinding all combination of the columns (question 77) and check the maximum covered rows by each of them and return the maximum.\n\n\n# Approach\n\n1, Generate all combinations of columns with a size of numSelect. For instance, for a matrix with 4 columns and k=2, the combinations are {{0,1}, {0,2}, {0,3}, {1,2}, {1,3}, {2,3}}.\n\n2, Store these column combinations in a vector of unordered_set.\n\n3, Iterate through the vector of combinations, and for each combination, call a helper function.\n\n4, Within the helper function, initialize the return value to the total number of rows. Loop through the matrix for all rows, skipping any unselected columns. As soon as a \'1\' is encountered, decrement the return value and move to the next row.\n\n# Complexity\n- Time complexity:\n\nComplexity of finding all of the combinations which is \n\nFinding combinations is a well-studied problem in combinatorics. The number of combinations of length k from a set of n elements is equal to the binomial coefficient, also known as "n choose k".\n\n(n, k)= n! / k! (n-k)!\n\n\u200BThen for each set of columns we iterate through the 2D matrix which means m * n * m\n\n\n- Space complexity:\n\nnumber of combinations * m\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    vector<unordered_set<int>> col_combs;\n    int maximumRows(vector<vector<int>>& m, int numSelect) {\n        find_combs(m[0].size(), numSelect);\n        int ret= 0;\n        for (int i=0; i<col_combs.size(); ++i)\n            ret= max(ret, covered_rows(m, col_combs[i]) ); \n        //print_combs();\n        return ret;\n    }\n\n    int covered_rows (vector<vector<int>>& m, unordered_set<int> & cols) {\n        int r = m.size();\n        int c = m[0].size();\n   \n        int ret= r;\n        for(int i= 0; i<r;++i) {\n            for(int j=0;j<c ;++j) {\n                if(cols.find(j) != cols.end()) {\n                    continue;\n                }\n                if (m[i][j] == 1) {\n                    ret--;\n                    break;\n                }\n            }\n        }\n        return ret;\n    }\n\n    void find_combs (int n,  int k) {\n        unordered_set<int> sol;\n        helper (n, 0, sol, k);\n    }\n\n    void print_combs() {\n        for(auto e: col_combs) {\n            for( auto ee: e) {\n                cout<<ee<<" ";\n            }\n            cout<<endl;\n        }\n    }\n\n    void helper(int n, int beg, unordered_set<int> &sol, int k) {\n        if(k==0) {\n            col_combs.push_back(sol);\n            return;\n        }\n        for(int i = beg ; i<n;++i) {\n            sol.insert(i);\n            helper(n, i+1, sol, k-1);\n            sol.erase(i);\n        }\n    }\n};\n```
['Backtracking', 'Combinatorics', 'C++']