public static int CountDecreasingPathsCell ( int mat [ ] [ ] , int dp [ ] [ ] , int n , int x , int y ) {
  if ( dp [ x ] [ y ] != - 1 ) return dp [ x ] [ y ] ;
  int delta [ ] [ ] = {
    {
      0 , 1 }, {
        1 , 0 }, {
          - 1 , 0 }, {
            0 , - 1 }
          };
          int newx , newy ;
          int ans = 1 ;
          for ( int i = 0 ;
          i < 4 ;
          i ++ ) {
            newx = x + delta [ i ] [ 0 ] ;
            newy = y + delta [ i ] [ 1 ] ;
            if ( newx >= 0 && newx < n && newy >= 0 && newy < n && mat [ newx ] [ newy ] < mat [ x ] [ y ] ) {
              ans += CountDecreasingPathsCell ( mat , dp , n , newx , newy ) ;
            }
          }
          return dp [ x ] [ y ] = ans ;
        }
        
public static int CountDecreasingPathsCell ( int mat [ ] [ ] , int dp [ ] [ ] , int n , int x , int y ) { if ( dp [ x ] [ y ] != - 1 ) return dp [ x ] [ y ] ; int delta [ ] [ ] = { { 0 , 1 } , { 1 , 0 } , { - 1 , 0 } , { 0 , - 1 } } ; int newx , newy ; int ans = 1 ; for ( int i = 0 ; i < 4 ; i ++ ) { newx = x + delta [ i ] [ 0 ] ; newy = y + delta [ i ] [ 1 ] ; if ( newx >= 0 && newx < n && newy >= 0 && newy < n && mat [ newx ] [ newy ] < mat [ x ] [ y ] ) { ans += CountDecreasingPathsCell ( mat , dp , n , newx , newy ) ; } } return dp [ x ] [ y ] = ans ; }
(method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (integral_type) name: (identifier) dimensions: (dimensions)) (formal_parameter type: (integral_type) name: (identifier) dimensions: (dimensions)) (formal_parameter type: (integral_type) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier))) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)) right: (unary_expression operand: (decimal_integer_literal)))) consequence: (return_statement (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) dimensions: (dimensions) value: (array_initializer (array_initializer (decimal_integer_literal) (decimal_integer_literal)) (array_initializer (decimal_integer_literal) (decimal_integer_literal)) (array_initializer (unary_expression operand: (decimal_integer_literal)) (decimal_integer_literal)) (array_initializer (decimal_integer_literal) (unary_expression operand: (decimal_integer_literal)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier)) declarator: (variable_declarator name: (identifier))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (decimal_integer_literal)) update: (update_expression (identifier)) body: (block (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (array_access array: (array_access array: (identifier) index: (identifier)) index: (decimal_integer_literal))))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (array_access array: (array_access array: (identifier) index: (identifier)) index: (decimal_integer_literal))))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (binary_expression left: (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (binary_expression left: (identifier) right: (identifier))) right: (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (binary_expression left: (identifier) right: (identifier))) right: (binary_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)) right: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier))))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier) (identifier) (identifier) (identifier))))))))) (return_statement (assignment_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)) right: (identifier)))))