Bitmasking | C++
\nclass Solution {\npublic:\n    int maximumRows(vector<vector<int>>& mat, int cols) {\n        int n = mat.size(), m = mat[0].size();\n        int len = (1 << 
```\nclass Solution {\npublic:\n    int maximumRows(vector<vector<int>>& mat, int cols) {\n        int n = mat.size(), m = mat[0].size();\n        int len = (1 << m), ans = 0;\n        for (int x = 1; x < len; x++)\n        {\n            // if the number of chosen columns does not equal cols skip it\n            if (__builtin_popcount(x) != cols)\n                continue;\n            set<int> invalid;\n            for (int i = 0; i < n; i++)\n                for (int j = 0; j < m; j++)\n                    if (mat[i][j] == 1 && !((x >> j) & 1))\n                        invalid.emplace(i);\n            ans = max(ans, n - (int)invalid.size());\n        }\n        return ans;\n    }\n};\n```
[]