Problem A of Gym is giving me a lot of trouble. I have reviewed my code multiple times and after several Wrong Answers I can't see the mistake. Any help is appreciated :) My submission
№ | Пользователь | Рейтинг |
---|---|---|
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 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
Problem A of Gym is giving me a lot of trouble. I have reviewed my code multiple times and after several Wrong Answers I can't see the mistake. Any help is appreciated :) My submission
Название |
---|
You did offset to avoid negative weights, but you actually don't avoid wmax > 802.
For example, in test
10000 500
1 1 100
1 1 100
...
// p[i] = 1, w[i] = 1, d[i] = 100 for all items
You will have in process states with wmax = 500 + 300 + 99 and 500 + 300 + 99 * 2, but your dp has sizes 10002 x 802 x 3. It is not good because you have line in your code:
So you need to change second dimension of dp to m + 2 * 300 or something about it.
P.S. Actually, this code with increasing of second dp dimension gives TL, because check
doesn't return "-INF" results and process "-INF" states every time. You need to change this code to:
to process only "-1" states.
Understood! Thank you very much, accepted now :) I will have more care with these "weird jumping" DP excercises the next time.