T-Systems interview question

Dp and recursion question.