Use dynamic programming to solve matrix chain multiplication problem and longest common substring problem (LCS problem)