Magical 1 string dynamic programming

hello sir can anyone please explain the approach to this probelem