Done prob18 with dynamics programming