I can't solve this problem: http://www.spoj.com/HSPL09/problems/HS09NLG/
Can the problem somehow be reduced to NIM game?
№ | Пользователь | Рейтинг |
---|---|---|
1 | jiangly | 3976 |
2 | tourist | 3815 |
3 | jqdai0815 | 3682 |
4 | ksun48 | 3614 |
5 | orzdevinwang | 3526 |
6 | ecnerwala | 3514 |
7 | Benq | 3482 |
8 | hos.lyric | 3382 |
9 | gamegame | 3374 |
10 | heuristica | 3357 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 169 |
2 | -is-this-fft- | 164 |
3 | Um_nik | 161 |
3 | atcoder_official | 161 |
5 | djm03178 | 157 |
6 | Dominater069 | 156 |
7 | adamant | 154 |
8 | luogu_official | 152 |
9 | awoo | 151 |
10 | TheScrasse | 148 |
I can't solve this problem: http://www.spoj.com/HSPL09/problems/HS09NLG/
Can the problem somehow be reduced to NIM game?
Название |
---|
Yes, you can use Sprague–Grundy theorem. To find the grundy numbers, you may use dp such as: dp(i, j) — grundy number for a stack with i stones and having taken j stones from this stack in the previous round. You may use j as 0 in the initial call, where you can take every but one stone from the stack. Then, you may precompute them in an array g[i] from 1 to 300 by calling g[i] = dp(i, 0). For a query, just xor the precomputed values and check whether it is 0.