Given: DP[i][j]=DP[i-1][j] + DP[i-1][j-1]*C[i]
I want to calculate DP[n][m]. I know I can compute all the DP[][] values, but I want a solution for typically larger N & M( upto 45000 ). Is there any way to do it faster ?
Given: DP[i][j]=DP[i-1][j] + DP[i-1][j-1]*C[i]
I want to calculate DP[n][m]. I know I can compute all the DP[][] values, but I want a solution for typically larger N & M( upto 45000 ). Is there any way to do it faster ?
I totally second the answer of Niklas B. in the aspect that the implementation cannot be made faster complexity-wise, however you could use memoization instead of 'true' dynamic programming. Although it does not improve the worst-case complexity, it potentially results in calculation of fewer intermediate values.
Time complexity-wise I don't think you can get much better without any additional information. However, you can compute the matrix row by row, leading to an improved space efficiency of O(m) instead of Ω(N * M):
DP[n][m]
will correspond tocurrent_row[m]
in the end