[JAVA] Beats 100%, BitMask + Backtraking, O(N!/(N-C)!)
\nclass Solution {\n    \n    private int ans;\n    \n    public int maximumRows(int[][] mat, int cols) {\n        var masks = new int[mat.length];\n        // 
```\nclass Solution {\n    \n    private int ans;\n    \n    public int maximumRows(int[][] mat, int cols) {\n        var masks = new int[mat.length];\n        // convert every row to bitmask\n        for (int r = 0; r < mat.length; r++) {\n            var mask = 0;\n            for (int c = 0; c < mat[r].length; c++)\n                if (mat[r][c] == 1)\n                    mask |= 1 << (mat[r].length - c - 1);\n            masks[r] = mask;\n        }       \n        // brute force all combination of columns\n        backtrack(0, 0, cols, mat[0].length, masks);\n        return ans;\n    }\n    \n    private void backtrack(int idx, int mask, int c, int limit, int[] masks) {\n        if (c == 0) {\n            // calculate ans\n            var count = 0;\n            for (int m : masks)\n                if ((mask | m) == mask)\n                    count++;\n            ans = Math.max(ans, count);\n            return;\n        }\n\n        if (idx == limit)\n            return; // nothing to do\n\n        // include current element\n        backtrack(idx + 1, mask | (1 << (limit - idx - 1)), c - 1, limit, masks);\n        \n        // exclude current element\n        backtrack(idx + 1, mask, c, limit, masks);\n    }\n}\n```
['Java']