Getting TLE with a python solution for Coin Combination problem in here
I know that python is slow ..., but have seen other python users solving it here
def solve(n, x, lst): dp =  for i in range(n+1): temp =  + *x dp.append(temp) for i in range(1, n+1): for j in range(1, x+1): dp[i][j] = (dp[i][j] + dp[i-1][j]) % mod if j - lst[i-1] >= 0: dp[i][j] = (dp[i][j] + dp[i][j - lst[i-1]]) % mod for i in dp: print(i) return dp[n][x] n, x = list(map(int, input().split())) lst = list(map(int, input().split())) print(solve(n, x, lst))
Creating the dp 2D array is even taking much time. Is there a way it can be optimized?
Thanks for taking your time and reading this!