Basic dynamic programming example.