How to solve this problem ? Please Help in Logic.

Please tell how to solve this problem and how should we code this ?
Problem

I’d say it’s dynamic programming: the min. number of letters necessary to represent substring [i…j] is DP[i][j].

dynamic prog.
Visit