Elements of Dynamic Optimization