Example of dynamic programming problem