Initialize DP table : dp [ i , j , j ] i : current position / index j : number of used elements k : number of unused elements
int [ , , ] dp = new int [ 101 , 101 , 101 ] ; for ( int i = 0 ; i < 101 ; i ++ ) { for ( int j = 0 ; j < 101 ; j ++ ) for ( int k = 0 ; k < 101 ; k ++ ) dp [ i , j , k ] = - 1 ; } return calculate ( 0 , 0 , N , P , M , dp ) ; }