Given an unsorted sequence A={a0,a1,a2,......an-1} of n integers. How do I find the longest increasing sub-sequence of the given sequence. Is there any dynamic programming solution.
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
Name |
---|
Do you need this solution?
A[i] - our sequence
DP[i] = the length of the LIS ending with element numbered i.
We'll keep track of vector V as follows:
V[j] = A[k], such that dp[k] = j and k is the largest number < i, satisfying this condition.
Suppose, we have found out all the dp[1..i-1], and V is up to date. How to find dp[i]? It's easy to find by binary search on V, isn't it? OK, find it, and don't forget to update V.
Start with dp[1] = 1 and V[1] = A[1] (1-based sequence)
I mean that when saying "By sorting all values we had before and binary search on them?".
1) override elements in V and
2) append elements to V.
You can try to solve it here: http://acm.tju.edu.cn/toj/showp2400.html