Getting tle with my code can u help me with it

u need to use dynamic programming :