Can some one explain LIS, a O(nlog(n)) solution clearly as i couldn't find more resources to learn clearly on internet
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 151 |
Can some one explain LIS, a O(nlog(n)) solution clearly as i couldn't find more resources to learn clearly on internet
Name |
---|
I learned it from this link
It's basic greedy idea is that you declare an array called "position", where the i'th element represent's the smallest number from the sequence that might be the last element in an increasing sub sequence with length
i
.e.g: 2, 5, 3, 7, 11,
all increasing sub sequences with length 1:
` 2
5
3
7
11 `
but the algorithm will choose 2 and assign it to index 1 of array position.
all increasing sub sequences with length 2:
` 2 5
2 3
2 7
2 11
5 7
5 11
3 7
3 11 `
we took 2 as the first element in a sub sequence of length 1 so we will discard all sub sequences that starts with 3 and 5
the algorithm will choose 3 as the best element and assign it to index 2 in array position
and so on, for each index in array position, the algorithm will greedly choose the least element not choosen yet to be the last element in a subsequence of length "index"
this is provably true because you will get a better chance to make the last sub sequence as long as possible by taking as small elements as you can in each index.
If the idea wasn't clear, please follow the steps of the algorithm in the above link on a piece of paper and you will get it.
short implementation
If you need only length
Explanation http://stackoverflow.com/a/2631810
That's not Petr!
I made a big mistake reading the name, sorry.