One more option is to not recurse at all, but to instead compute the sequence until we get the desired term. This not only avoids the original algorithm's exponential complexity; it also avoids the at least linear (in terms of counting values) memory complexity of memoization. (Recursion/memoization can also run into implementation-specific issues such as recursion depth errors or memory errors, which are not a concern with the code below.)
def T(n): if n<=0: return 1 # Set a, b to T(-1), T(0) a, b = 1, 1 for i in range(n): # Change a, b from T(i-1), T(i) to T(i), T(i+1) a, b = b, b+i*a # i=n-1 set b to T(n) return b