I am not getting any idea how to approach this problem Please help https://codeforces.me/problemset/problem/234/C
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3773 |
3 | Radewoosh | 3646 |
4 | ecnerwala | 3624 |
5 | jqdai0815 | 3620 |
5 | Benq | 3620 |
7 | orzdevinwang | 3612 |
8 | Geothermal | 3569 |
8 | cnnfls_csy | 3569 |
10 | Um_nik | 3396 |
# | User | Contrib. |
---|---|---|
1 | Um_nik | 164 |
2 | maomao90 | 160 |
3 | -is-this-fft- | 159 |
4 | atcoder_official | 158 |
4 | cry | 158 |
4 | awoo | 158 |
7 | adamant | 155 |
8 | nor | 154 |
9 | maroonrk | 151 |
10 | Dominater069 | 150 |
I am not getting any idea how to approach this problem Please help https://codeforces.me/problemset/problem/234/C
Name |
---|
I used two-dimensional dp: dp[i][0] — if we continue negative sequence at index i dp[i][1] — if we continue positive sequence at index i
"state" is the number of changes needed to maintain a positive or negative sequence. Depending on the first element of the array we set base cases. Also, the last element of the sequence must be positive.
112223468
I prefer suffix-prefix sollution.
In fact, you don't even need dp. You need need to count the number of less than or equal to 0 and greater than or equal to 0s. The rest is unnecessary, and it's total possible without DP.
I also prefer this solution, but the author asked for dp approach.