Unable to solve this problem.

Please help me in solving this problem. SPOJ.com - Problem FP
This is a typical dp problem , but my solution is getting TLE. I am unable to optimize it further. Please help me in solving this problem.
My solution : faMyky - Online C++0x Compiler & Debugging Tool - Ideone.com