Using memoization to avoid re - computation
if ( prev != - 1 && dp [ i ] [ prev ] [ k ] != - 1 ) { return dp [ i ] [ prev ] [ k ] ; } int include = 0 ; if ( prev == - 1 a [ i ] >= a [ prev ] ) { int k2 = k ;