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 | 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 | djm03178 | 152 |
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