Here is a link to the problem: http://www.spoj.com/problems/ACPC10D/ I have used DP and made the necessary optimizations however I still get a TLE. Here is my code: http://ideone.com/ASwkh0
Please clarify the cause behind getting a TLE and how it can be handled. Any help and suggestions to improve my code would be extremely helpful. Thank you.