How Does Dynamic Programming Work