Initialize the memorization table
int [ , ] memo = new int [ nums . Length + 1 , 2 * sum + 1 ] ; for ( int i = 0 ; i < memo . GetLength ( 0 ) ; i ++ ) { for ( int j = 0 ; j < memo . GetLength ( 1 ) ; j ++ ) { memo [ i , j ] = int . MinValue ; } } return dfs ( memo , nums , S , 0 , 0 , sum ) ; }