LCS algorithm making use of dynamic programming