recurrence and dynamic prog