Dynamin Programming problem on SPOJ- BORW

I’m trying to solve a DP question on spoj, SPOJ.com - Problem BORW
.I have tried my best to memoize all the states, still its giving TLE. PLZ help…
Code : Vvk3fh - Online C++0x Compiler & Debugging Tool - Ideone.com

please tell your approach first,doing that can save time!

problem is solved! Thanks anyway…

hi @amulyagaur , if you have solved that with dp , can you please share your solution ??

Sure! MjTflM - Online C++ Compiler & Debugging Tool - Ideone.com