dyamic programming is beautiful