The real hard part is solving the recursive backtracking problem.
Once we have the recurrences, it’s rather mechanical to convert backtracking into dynamic programming.
Indeed, we should also prove the optimal substructure property to show that the results we memoize are actually useful. But if we are in a time crunch simply assume this property holds.
This is the difficult part. Don’t proceed further until the correct recurrence is found.
If we are actually implementing a DP problem in code, implement the recurrence with brute force recursion first, make sure it’s correct by testing small inputs, then move on to the DP conversion step.
Otherwise it becomes impossible to debug.
From the recurrence, we need to observe the parameters of:
@EX
Different ParametersThen we can compare the parameters of the current call with the recursive calls to see the order.
@EX
Finding Order of EvaluationNow we iterate over all possible combinations of backtracking parameters.
No nested for loops. The DP data structure is likely an 1D array and the for loop goes in the order of evaluation.