Set all values of dp to - 1 ;
for ( int i = 0 ; i < MAX ; i ++ ) for ( int j = 0 ; j < MAXP + 1 ; j ++ ) for ( int k = 0 ; k < MAXK ; k ++ ) for ( int l = 0 ; l < MAXPREV + 1 ; l ++ ) dp [ i ] [ j ] [ k ] [ l ] = - 1 ;