Spoj Problem Two Ends (Code : TWENDS)

Algorithm - DP
Problem Link :
http://www.spoj.com/problems/TWENDS/