T-Systems Interview Question

Dp and recursion question.