Thursday, October 6, 2011

SRM 520 div2

Haven't been coding for a while so I picked SRM 520 div2 for a warm up. It seems topcoder's div2 problem is becoming easier, while I still haven't had a p500 in div1 yet.

p250 and p500 have very small instances so you can brute-force by enumerating all possible solutions.

p1000 is a very straightforward DP, just observe that you can work row by row and only need to remember previous row's pass and challenged counts. However, my solution simply won't pass the last testcase, and it is not for integer overflow. The real issue? I created DP array dp[55][4][4], which ought to be enough, but I made the first recursive call with (0,10,0), which index something dp[0][10][0]. And this is a disaster. After staring at the code for quite some time and printed some intermediate results, still no idea where went wrong. Looking at a few submitted solution and they have implemented the same thing. And finally, I realized that the first call recurse(0,10,0) is the culprit, and it passed.

OK, in the end I am happy to see all three problems passed.

No comments:

Post a Comment