Maximum Rows Covered by Columns Solution Java
class Solution {\n  public int maximumRows(int[][] matrix, int numSelect) {\n    dfs(matrix, /colIndex=/0, numSelect, /mask=/0);\n    return ans;\n  }\n\n  priv
class Solution {\n  public int maximumRows(int[][] matrix, int numSelect) {\n    dfs(matrix, /*colIndex=*/0, numSelect, /*mask=*/0);\n    return ans;\n  }\n\n  private int ans = 0;\n\n  private void dfs(int[][] matrix, int colIndex, int leftColsCount, int mask) {\n    if (leftColsCount == 0) {\n      ans = Math.max(ans, getAllZerosRowCount(matrix, mask));\n      return;\n    }\n    if (colIndex == matrix[0].length)\n      return;\n\n    // choose this column\n    dfs(matrix, colIndex + 1, leftColsCount - 1, mask | 1 << colIndex);\n    // not choose this column\n    dfs(matrix, colIndex + 1, leftColsCount, mask);\n  }\n\n  int getAllZerosRowCount(int[][] matrix, int mask) {\n    int count = 0;\n    for (int[] row : matrix) {\n      boolean isAllZeros = true;\n      for (int i = 0; i < row.length; ++i) {\n        if (row[i] == 1 && (mask >> i & 1) == 0) {\n          isAllZeros = false;\n          break;\n        }\n      }\n      if (isAllZeros)\n        ++count;\n    }\n    return count;\n  }\n}\n
['Array', 'Backtracking', 'Bit Manipulation', 'Matrix', 'Enumeration']