hi everyone!!i have been facing some TLE issues while solving dp problem in python…
ill share the question link and my code here.
- n, k = [int(i) for i in input().split()]
- dp = [[-1]*(2005) for i in range(2005)]
- MOD=10**9+7
- def solve(x,k):
- if(k==0):
- return 1
- elif(dp[x][k]!=-1):
- return dp[x][k]
- ans=0
- for i in range(x,n+1,x):
- ans+=solve(i,k-1)
- dp[x][k]=ans%MOD
- return dp[x][k]
- res=solve(1,k)
- print(res)
i used top down approach it throws tle.when i changed the recursionlimit to 10**6 and added threading but it throws memory limit exceeded…can anyone help me out this… and please dont tell me to code in iterative manner coz im just a beginner…