implement longest common subsequence using dynamic programming