№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 3757 |
2 | jiangly | 3647 |
3 | Benq | 3581 |
4 | orzdevinwang | 3570 |
5 | Geothermal | 3569 |
5 | cnnfls_csy | 3569 |
7 | Radewoosh | 3509 |
8 | ecnerwala | 3486 |
9 | jqdai0815 | 3474 |
10 | gyh20 | 3447 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | maomao90 | 171 |
2 | awoo | 165 |
3 | adamant | 163 |
4 | TheScrasse | 159 |
5 | maroonrk | 155 |
6 | nor | 154 |
7 | -is-this-fft- | 152 |
8 | Petr | 147 |
9 | orz | 146 |
10 | pajenegod | 145 |
Название |
---|
Maybe it's because the maximum length of the string is 25? Though you can solve this problem with dynamic programming in O(N3) with the same recurrence relation using memoization.
There are 2^26-2 = 67108862 states, and what you do in one state is linear. Can you explain why it's O(N^3)?
Let
Unable to parse markup [type=CF_TEX]
be a boolean function that tells us if we can reduce the substringUnable to parse markup [type=CF_TEX]
. Also define functionUnable to parse markup [type=CF_TEX]
andUnable to parse markup [type=CF_TEX]
, whereUnable to parse markup [type=CF_TEX]
the largest indexUnable to parse markup [type=CF_TEX]
such thatUnable to parse markup [type=CF_TEX]
, andUnable to parse markup [type=CF_TEX]
as the lowest left index with the mentioned property.Now here's the code for the recurence:
(There are also some cornes cases)
We observe that if
Unable to parse markup [type=CF_TEX]
then we can transition to stateUnable to parse markup [type=CF_TEX]
and see if we can reduce the substringUnable to parse markup [type=CF_TEX]
. But also we can combine the substringUnable to parse markup [type=CF_TEX]
with some other substringUnable to parse markup [type=CF_TEX]
if all their characters are equal. So we are left to reduceUnable to parse markup [type=CF_TEX]
andUnable to parse markup [type=CF_TEX]
. We useUnable to parse markup [type=CF_TEX]
andUnable to parse markup [type=CF_TEX]
because it's always better to pick these indeces instead of fixing the right point of an interval and try to extend it to the left until we get to a different character.I know that I worded it pretty badly, but try to simulate the recurrence on the examples and it should become clear why this kind of approach works. (but take notice, I'm not 100% sure that this solution is correct)