This is really similar to Fibonacci Sequence problem. I understand the DP optimization with Fibonacci function using the for loop, but I'm having hard time to connect to this problem.
The recursion function I want to optimize is:
def cal(n): if n <= 0: return 1 else: return cal(n-25)+cal(n-26)
from itertools import lru_cachethen add@lru_cachedecorator before your function. all done ✅from itertools...line 2)@lru_cache, line 3)def cal(n): ..., line 4)print(cal(some_number))