LCS using memoization