Need help in SPOJ Problem

Can someone please help me with this question . I can’t even figure out the states for the dp.