Computing time-complexity of DP recursion

467 Views Asked by At

I've written an algorithm which uses 3-dimensional DP table and it goes as follows:

$DP[i][j][0]$ can be computed in $O(1)$ for any $i,j$ and

$DP[i][j][k]=\max(DP[i][m][0]+DP[m+1][j][k-1]) $ for all $i\leq m \leq j-1$

How to compute its time-complexity?

1

There are 1 best solutions below

0
On BEST ANSWER

I can compute $DP[i][j][k]$ in $O(N^2)$. To see this, note that the first term of the summation ($DP[i][m][0]$) can always be computed in $O(1)$, and the second term of the second term of the summation ($j$ from $DP[m+1][j][k-1]$)... is always $j$.

...assuming everything is memoized, of course.