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 | 3831 |
3 | Radewoosh | 3646 |
4 | jqdai0815 | 3620 |
4 | Benq | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | gamegame | 3386 |
10 | ksun48 | 3373 |
# | User | Contrib. |
---|---|---|
1 | cry | 164 |
1 | maomao90 | 164 |
3 | Um_nik | 163 |
4 | atcoder_official | 160 |
5 | -is-this-fft- | 158 |
6 | awoo | 157 |
7 | adamant | 156 |
8 | TheScrasse | 154 |
8 | nor | 154 |
10 | Dominater069 | 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