Dynamic Programming is an existing programming approach aimed at finding efficient solutions in which each sub-solution is solved only once, which we interpret by dividing problems into smaller parts in order to find optimal solutions, interpreting them from the top down or from the bottom up, saving previous solutions and…