Mam Im trying this question by recursion but im getting the please help

Mam Im trying this question by recursion but im getting tle please help

https://hack.codingblocks.com/app/contests/2138/1066/problem

ur recursive code is correct, u need to use dynamic programming to optimise it furthur and to pass all test case