Why my code is getting TLE

i don’t understand why TLE occur.
please see my code

@S18CRX0174
Time complexity of your f() function is very high. try to optimise it. Also you forgot to write dp[i][j]=result; at the end of function.

ok i have corrected it ,but still TLE

according to given solution, solve function is called n times, and i am also calling my f function n times so what is the main problem