C++ Bitmask O(n*2^n) 7ms
Whenever you see n <= 12, start typing for (int mask = 0; mask < (1 << n); mask++).\nc++\nclass Solution {\npublic:\n    int maximumRows(vector<vector<int>>& ma
Whenever you see `n <= 12`, start typing `for (int mask = 0; mask < (1 << n); mask++)`.\n``` c++\nclass Solution {\npublic:\n    int maximumRows(vector<vector<int>>& mat, int cols) {\n        int n = mat.size(), m = mat[0].size();\n        vector<int> rows(n);\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < m; j++) {\n                if (mat[i][j] == 1) {\n                    rows[i] |= (1 << j);\n                }\n            }\n        }\n        int ans = 0;\n        for (int mask = 0; mask < (1 << m); mask++) {\n            if (__builtin_popcount(mask) != cols) continue;\n            int cur = 0;\n            for (int i = 0; i < n; i++) {\n                if ((mask | rows[i]) == mask) cur++;\n            }\n            ans = max(ans, cur);\n        }\n        return ans;\n    }\n};\n```
['C', 'Bitmask']