Help with a problem: Digit DP

I tried solving the following question:
https://www.spoj.com/problems/RAONE/

This is my solution:
https://ideone.com/mZRp0n

This works for all cases when I don’t use DP. But it gives WA when I use DP. I saw some solutions but I couldn’t understand where I’m wrong. Can someone explain where I’m wrong?

Note:
Indexing starts from the unit position.