Hello, I am unable to figure out how I can formulate DP for this problem (https://codeforces.com/problemset/problem/467/C). Thank you!
# | User | Rating |
---|---|---|
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 |
# | User | Contrib. |
---|---|---|
1 | maomao90 | 171 |
2 | awoo | 164 |
2 | adamant | 164 |
4 | TheScrasse | 159 |
5 | nor | 154 |
5 | maroonrk | 154 |
7 | -is-this-fft- | 152 |
8 | Petr | 147 |
9 | orz | 146 |
10 | pajenegod | 145 |
Hello, I am unable to figure out how I can formulate DP for this problem (https://codeforces.com/problemset/problem/467/C). Thank you!
Name |
---|
You can think it like this:
If you are at index i and you need x pairs, you have two options: 1) take the sum of the next m elements, move to index i+m and now look for x-1 pairs 2) move to index i+1 and look for x pairs
That can be written as a dp with two states: the index in the array and the number of pairs you need
dp[i][k] = max(dp[i+1][k], dp[i+m][k-1] + sum(A[i], A[i+1], ... , A[i+m-1]) )
Okay, got it now... got confused with ranges(thought they could collide).. thanks for the help!