Initialise dp array
vector < vector < int > > dp ; dp . resize ( n + 1 , vector < int > ( n + 1 ) ) ; for ( int i = 0 ; i < n + 1 ; i ++ ) { for ( int j = 0 ; j < n + 1 ; j ++ ) { dp [ i ] [ j ] = -1 ; } }