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.
# | User | Rating |
---|---|---|
1 | jiangly | 3977 |
2 | tourist | 3815 |
3 | jqdai0815 | 3682 |
4 | ksun48 | 3614 |
5 | orzdevinwang | 3526 |
6 | ecnerwala | 3514 |
7 | Benq | 3483 |
8 | hos.lyric | 3381 |
9 | gamegame | 3374 |
10 | heuristica | 3358 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | -is-this-fft- | 162 |
3 | Um_nik | 161 |
4 | atcoder_official | 159 |
5 | djm03178 | 157 |
6 | Dominater069 | 156 |
7 | adamant | 154 |
8 | luogu_official | 152 |
8 | awoo | 152 |
10 | TheScrasse | 148 |
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.
Name |
---|
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://mirror.codeforces.com/contest/1842/submission/217094157