On submission, It works fine for 90%+ testcases under each subtask but the final score is 20, since I got a WA some...PLEASE HELP!!!
using namespace std; int main() {
I know of the O(n^3) & the O(n^4) solutions. Given the constraints, they should work... But my solutions is, in fact, O(n^2). The method is called GRAPH CUTTING. It is a very correct algorithm. There are probably slight mistakes in memory allocation, implementation of the algorithm etc. So, I need help in debugging the solution...So please try to...THANKS!!! asked 05 Jan '15, 23:07

@arpanb8 , When you use
The value stored in ans[p][q] may exceed the integer limits, and that is a possible reason for the 'wrong answer'. So, you must make sure that it is small, and still get the correct answer, and the best way to do that is :
And this will work as, (a%c + b%c)%c = (a+b)%c, and ans[p][q] will always be inside the limits (0  20010).
Also, answered 08 Jan '15, 13:09

Hi, No! Stop using next_permutation for each problem. This is again a dynamic programming problem. Try thinking of the number of ways to reach a particular (x, y) with a certain number of consecutive moves (for both directions allowed), and how to formulate that in terms of smaller (x, y). Cheers. answered 05 Jan '15, 23:21
1
@arpanb8 My answer, unfortunately, still holds. Try to think a bit more! Think in four dimensions  a particular (x, y), coming from left/right, with 0 to K consecutive moves. If you want the complete answer, say so. :)
(15 Jan '15, 23:28)

Yeah, Somebody Please answer...