Help debug dynamic programming problem!

Revision en3, by lvisbl_, 2024-11-01 02:22:58

Recently, I have encounter this dynamic programming problem and I can not debug where I have problem, I used forward DP style and I have checked the transition and base case. Please help me to look at it, I'm so frustrating. Thank in advance.

Problem link: leetcode

My code:

code

Updated fix my problem: my for loop only run until i = n, but the final dp state which is dp[n + 1][m + 1] can be reached from dp[n + 1][m] => My for loop should run till n + 1 so this relaxation can happen.

fixed
Tags dynamic programming

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English lvisbl_ 2024-11-01 02:22:58 55
en2 English lvisbl_ 2024-11-01 02:22:16 1318
en1 English lvisbl_ 2024-10-31 22:45:38 1524 Initial revision (published)