I am trying to set an array of integer whose size is 10000.
However, Code works great if the length of the array a
is less than 1995.
If I changed it to 2000 or more program stops working.
I want this code to work if I set array a
of size 10000.
Here is the Python code:
import random
random.seed()
a = [random.randint(-1000, 1000) for i in range(10000)]
DP = [[] for i in a]
seq = []
def solveDP(i):
global DP
if i >= len(a):
return []
if len(DP[i]) > 0:
return DP[i]
arr1 = [a[i]] + solveDP(i + 2)
arr2 = solveDP(i + 1)
if sum(arr1) > sum(arr2):
DP[i] = arr1[:] # Copy arr1 into DP[i]
else:
DP[i] = arr2[:] # Copy arr2 into DP[i]
return DP[i]
print(solveDP(0))