Initialize dp array with - 1
for ( int i = 0 ; i < 1024 ; i ++ ) { for ( int j = 0 ; j < 10 ; j ++ ) { for ( int k = 0 ; k < 2 ; k ++ ) { for ( int l = 0 ; l < 2 ; l ++ ) dp [ i , j , k , l ] = - 1 ; } } }