In todays LeetCode challenge, (LeetCode Problem L-1293, My first idea was to go with backtracking, and then use memoization to make it qudratic or cubic from exponential.
But, the dp gave wrong ans while the recursion gave the right one.
After thinking a bit, I can kind of understand where this might go wrong, but I wanted confirmation. So I think that during backtracking on a branch, I am putting the current ans in the dp, but when I am coming to try again from another branch, it sees that there is already calculated and has a ans, and so it takes that ans instead of trying to do its job.
So I get this, so is there any way to fix this, or is it not possible to use memoization in these baxktracking questions?
Thanks.
////////////////////////////////////////////////////////////////////