Brute-Force + Bit Magic
\nLow constraints give away a brute-force solution.\n    \nWe try all combinations of columns (using a bit mask), where the number of columns does not exceed co
\nLow constraints give away a brute-force solution.\n    \nWe try all combinations of columns (using a bit mask), where the number of columns does not exceed `cols`.\n    \nFor each combination, we count covered rows, and return the maximum.\n    \nAs an optimization, we can only consider bit masks with `cols` bits. We start from `(1 << cols) - 1`.\n\nThen, we use `next_popcount` to get the next mask with the same number of bits.\n    \n**C++**\n```cpp\nint next_popcount(int n) {\n    int c = (n & -n), r = n + c;\n    return (((r ^ n) >> 2) / c) | r;\n}\nint maximumRows(vector<vector<int>>& mat, int cols) {\n    int m = mat.size(), n = mat[0].size(), res = 0;\n    for (int mask = (1 << cols) - 1; mask < (1 << n); mask = next_popcount(mask)) {\n        int rows = 0;\n        for (int i = 0, j = 0; i < m; ++i) {\n            for (j = 0; j < n; ++j)\n                if (mat[i][j] && (mask & (1 << j)) == 0)\n                    break;\n            rows += j == n;\n        }\n        res = max(res, rows);\n    }\n    return res;\n}
[]