static int countString ( int m , int n , String [ ] arr , int i ) {
  if ( m < 0 || n < 0 ) {
    return Integer . MIN_VALUE ;
  }
  if ( i >= arr . length ) {
    return 0 ;
  }
  if ( dp [ m ] [ n ] [ i ] != - 1 ) {
    return dp [ m ] [ n ] [ i ] ;
  }
  int zero = 0 , one = 0 ;
  for ( char c : arr [ i ] . toCharArray ( ) ) {
    if ( c == '0' ) {
      zero ++ ;
    }
    else {
      one ++ ;
    }
  }
  int x = 1 + countString ( m - zero , n - one , arr , i + 1 ) ;
  int y = countString ( m , n , arr , i + 1 ) ;
  return dp [ m ] [ n ] [ i ] = Math . max ( x , y ) ;
}

static int countString ( int m , int n , String [ ] arr , int i ) { if ( m < 0 || n < 0 ) { return Integer . MIN_VALUE ; } if ( i >= arr . length ) { return 0 ; } if ( dp [ m ] [ n ] [ i ] != - 1 ) { return dp [ m ] [ n ] [ i ] ; } int zero = 0 , one = 0 ; for ( char c : arr [ i ] . toCharArray ( ) ) { if ( c == '0' ) { zero ++ ; } else { one ++ ; } } int x = 1 + countString ( m - zero , n - one , arr , i + 1 ) ; int y = countString ( m , n , arr , i + 1 ) ; return dp [ m ] [ n ] [ i ] = Math . max ( x , y ) ; }
(method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (integral_type) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier)) (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier))) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) consequence: (block (return_statement (field_access object: (identifier) field: (identifier))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (field_access object: (identifier) field: (identifier)))) consequence: (block (return_statement (decimal_integer_literal)))) (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)) index: (identifier)) right: (unary_expression operand: (decimal_integer_literal)))) consequence: (block (return_statement (array_access array: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)) index: (identifier))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal)) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (enhanced_for_statement type: (integral_type) name: (identifier) value: (method_invocation object: (array_access array: (identifier) index: (identifier)) name: (identifier) arguments: (argument_list)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (character_literal))) consequence: (block (expression_statement (update_expression (identifier)))) alternative: (block (expression_statement (update_expression (identifier))))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (decimal_integer_literal) right: (method_invocation name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (identifier)) (binary_expression left: (identifier) right: (identifier)) (identifier) (binary_expression left: (identifier) right: (decimal_integer_literal))))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier) (identifier) (binary_expression left: (identifier) right: (decimal_integer_literal)))))) (return_statement (assignment_expression left: (array_access array: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)) index: (identifier)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (identifier)))))))