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 | 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 |
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.