Dynamic Programming21 sections · 916 units
Open in Course

Lessons from LIS

summary

Three patterns to remember from LIS (Longest Increasing Subsequence):

1.1. "Ending at ii" states let you know exactly what to extend from. This pattern appears in many subsequence problems.

2.2. The answer might not be at the last index. Check if you need max(dp)\max(dp) or dp[n1]dp[n-1].

3.3. Picking the locally best option fails when those choices affect future options. DP (dynamic programming) explores all paths. The O(n2)O(n^2) solution works for n2500n \le 2500. For larger inputs, you need the O(nlogn)O(n \log n) improvement.