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 | 3845 |
2 | jiangly | 3707 |
3 | Benq | 3630 |
4 | orzdevinwang | 3573 |
5 | Geothermal | 3569 |
5 | cnnfls_csy | 3569 |
7 | jqdai0815 | 3532 |
8 | ecnerwala | 3501 |
9 | gyh20 | 3447 |
10 | Rebelz | 3409 |
# | User | Contrib. |
---|---|---|
1 | maomao90 | 171 |
2 | awoo | 163 |
3 | adamant | 162 |
4 | maroonrk | 152 |
5 | nor | 151 |
5 | -is-this-fft- | 151 |
7 | atcoder_official | 147 |
7 | TheScrasse | 147 |
9 | Petr | 145 |
10 | pajenegod | 144 |
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