Dynamic Programming: A Discrete Calculus of Variations