Can anyone please explain how to solve this question by DP.
I have read the tutorial of this problem but still can't get the intuition.
Or please suggest similar question question to get the intuition.
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 166 |
2 | maomao90 | 163 |
2 | Um_nik | 163 |
4 | atcoder_official | 161 |
5 | adamant | 160 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | nor | 153 |
9 | Dominater069 | 153 |
Can anyone please explain how to solve this question by DP.
I have read the tutorial of this problem but still can't get the intuition.
Or please suggest similar question question to get the intuition.
Название |
---|
atleast share problem link
Okay so you can store dp[i] as the number of max balls that can be removed till that place eg 4 6 6 8 6 4 dp[0] = 0 (base) dp[1] = 0 (just one 4 so nothing happens) dp[2] = 0 (again nothing happens) dp[3] = 2 (both 6) dp[4] = 2 dp[5] = 4 dp[6] = 6
so basically for calculating dp[5] suppose for value 6 i find previous 6 6 was present at 2 and 3 index so ans for dp[5] = max(dp[1] + (5-2)+1) and dp[2] + (5-3)+1 and ofc dp[5] = max(dp[5], dp[4])
so i will have to calculate for all possible occurences of 6 before this will give n2 solution which can be optimized using priority queue now you know the ans is determined by dp[index] and diff in index try putting a custom comparator for your priorty queue such that the first value you pop will always be the ans you will get max dp with
heres my solution https://codeforces.net/contest/1842/submission/217094157