Algorithm of Dp

qstn

can anyone explain this editorial please also give recursive relation for the problem.