Optimal Control of Discrete Systems