2
$\begingroup$

In any dynamic programming problem can there exist more than one optimal state ?

If so how would I enumerate all of them ?

For example: in the subset sum problem for the given set $\{-3, -2, 7, 5\}$ and target sum $0$.

There exists two ways of reaching $0$. ie. $\{\}$ = empty set as a sum of zero, or $\{-3, -2, 5\}$ = also which has a sum of $0$.

In dynamic programming how would you distinguish between these two ?

$\endgroup$
4
$\begingroup$

Yes, but it's implicit in the dynamic programming table.

The dynamic programming table starts by filling out objective values for trivial sub-solutions, then combining them to obtain the optimum objective value by the time the final entry is reached. The central part to emphasise here is that the dynamic programming table has objective values as its entries, rather than the sub-solutions themselves (although you may hang on to all sorts of information to help the computation of course). So the way you obtain the actual solution from a dynamic programming table is to trace back from the final entry reconstructing the steps taken to get there.

Then if there's multiple ways to get there, in the tracing you just run into situations where you can go more than one way. If you were only interested in obtaining some solution, you just pick a route. If you want all of them, you exhaustively explored all routes back through the table.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.