Problem Link: http://www.spoj.com/problems/NUMTSN/
My solution: http://ideone.com/7fKLqx
Any help is really appreciated.
# | 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 | 164 |
1 | maomao90 | 164 |
3 | Um_nik | 163 |
4 | atcoder_official | 160 |
4 | adamant | 160 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
8 | Dominater069 | 154 |
8 | nor | 154 |
Problem Link: http://www.spoj.com/problems/NUMTSN/
My solution: http://ideone.com/7fKLqx
Any help is really appreciated.
Name |
---|
Here's my code.
A common trick for multi-test problems: if you reverse the direction of your DP (such that DP[...] is in how many ways you can finish the number if your current state is [...]), then the value of states with sa=sb=1 does not depend on either A or B. This allows you to precompute the value of those states for all test cases, and for a specific case you only need to care about states with sa or sb equal to 0 (which should be very few).
Sometimes (and in this specific problem), formulating the DP in reverse should also allow you to find a faster solution for the single-test case.
can you explain this trick more?