Stores the values of overlapping subproblems
int [ , , ] dp = new int [ M , M , 2 ] ; for ( int i = 0 ; i < M ; i ++ ) for ( int j = 0 ; j < M ; j ++ ) for ( int k = 0 ; k < 2 ; k ++ ) dp [ i , j , k ] = - 1 ; Console . WriteLine ( countNum ( N , 0 , K , 0 , dp ) ) ; } }