On the theory of dynamic programming