[JAVA] Bit-mask backtracking
\nclass Solution {\n    int max = 0;\n    int mask = 1073741823;\n    int n;\n    public int maximumRows(int[][] mat, int cols) {\n        int[] state = new int
```\nclass Solution {\n    int max = 0;\n    int mask = 1073741823;\n    int n;\n    public int maximumRows(int[][] mat, int cols) {\n        int[] state = new int[mat.length];\n        n = mat[0].length;\n        for (int i = 0; i < mat.length; i++) {\n            for (int j = 0; j < mat[0].length; j++) {\n                state[i] <<= 1;\n                state[i] += mat[i][j];\n            }\n        }\n        backtrack(state, cols, 0);\n        return max;\n    }\n    \n    public void backtrack(int[] state, int cols, int pos) {\n        if (pos == n || cols == 0) {\n            int count = 0;\n            for (int i = 0; i < state.length; i++) {\n                if (state[i] == 0) count++;\n            }\n            max = Math.max(count, max);\n            return;\n        }\n        \n        // choose col\n        int[] copystate = new int[state.length];\n        for (int i = 0; i < state.length; i++) {\n            copystate[i] = state[i] & (mask ^ (1 << pos));\n        }\n        backtrack(copystate, cols-1, pos+1);\n        \n        // don\'t choose col\n        backtrack(state, cols, pos+1);\n    }\n}\n```
['Backtracking', 'Bitmask']