DSALearningseries - DPbasic - Billards

Hello , I am learning DP, and am stuck at the memoization part of the problem.
Also can someone review my code also.
I want to improve and learn more.

link - CodeChef: Practical coding for everyone
code -
def val(n,f):

if n == f and n != 0: 
    return 1

elif f > n :
    return 0
    
return val(n,f+3)+val(n,f+2)

t = int(input())
for i in range(t):
n = int(input())
print(val(n,0))

Thanks