I am not getting any idea how to approach this problem Please help https://codeforces.net/problemset/problem/234/C
# | User | Rating |
---|---|---|
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 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
2 | maomao90 | 163 |
4 | atcoder_official | 161 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | nor | 153 |
9 | Dominater069 | 153 |
I am not getting any idea how to approach this problem Please help https://codeforces.net/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.