A numerical method for hybrid optimal control based on dynamic programming