SRM 547 - Div2 - 500 - PillarsDivTwo

I am trying to solve the following problem - http://community.topcoder.com/stat?c=problem_statement&pm=12075&rd=14739
using the dynamic programming approach, and I have written down the following code to solve the problem, but unfortunately it fails on a couple of test cases when I run the practice tests in the practice room, can anybody point out the flaw in my approach to solving this problem or suggest a tweak if there is any error in coding. I have commented the code at appropriate places to make the approach clear. Here is the link to the topcoder forum for the same problem - http://apps.topcoder.com/forums/?module=Thread&threadID=807928&start=0&mc=1#1828532

http://codekhal.wordpress.com/tag/pillarsdivtwo/
this link will help in dp approach :slight_smile:

//