Hello Everyone,
I have figured out a DP solution for this problem which is working for all available test cases from spojtoolkit.
but i have got Time Limit Exceeded.
For my dp case, i used a map for the cache purpose.
Here is the code
Can any one check and help me regarding how to make much more efficient to run in 2sec.(as per problem)