The array used by the DP solution is almost always based on the size of the state space of the problem, that is, the allowable values for each of its parameters
for instance
fib[i+2] = fib[i+1] + fib[i]
Same as
def fib(i): return fib(i-1)+fib(i-2]
You can make this more obvious by doing memoization in your recursive functions
def fib(i): if( memo[i] == null ) memo[i] = fib(i-1)+fib(i-2) return memo[i]
If your recursive function has parameters K, you probably need a K-dimensional matrix.
source share