Initialize the dp array with - 1 Fill each row with - 1.
for ( int i = 0 ; i < dp . GetLength ( 0 ) ; i ++ ) { for ( int j = 0 ; j < dp . GetLength ( 1 ) ; j ++ ) { for ( int k = 0 ; k < dp . GetLength ( 2 ) ; k ++ ) dp [ i , j , k ] = - 1 ; } }