From Shortest Paths to Reinforcement Learning: A MATLAB-Based Introduction to Dynamic Programming