memoized version - Top Down