Because both the greedy and dynamic-programming strategies exploit optimal substructure,
you might be tempted to generate a dynamic-programming solution to a
problem when a greedy solution suffices or, conversely, you might mistakenly think
that a greedy solution works when in fact a dynamic-programming solution is required.
To illustrate the subtleties between the two techniques, let us investigate
two variants of a classical optimization problem.