3. Set the base cases
You process the array from left to right, and because:
- You have not selected any number yet.
- No subsequence has been built yet.
So:
dp[v] = 0for every possible vlast_pos[v] = -1(any non-possible entry)prev[i] = -1for all ibest_end = -1- It's the index where the optimal subsequence ends.best_len = 0- It's the length of the optimal subsequence ending atbest_end
These initializations make sure every value starts empty before you process the first element.