The art and theory of dynamic programming