Implemented the matching parentheses with dynamic programming