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 | 3993 |
2 | jiangly | 3743 |
3 | orzdevinwang | 3707 |
4 | Radewoosh | 3627 |
5 | jqdai0815 | 3620 |
6 | Benq | 3564 |
7 | Kevin114514 | 3443 |
8 | ksun48 | 3434 |
9 | Rewinding | 3397 |
10 | Um_nik | 3396 |
# | 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 | 155 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
10 | nor | 152 |
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