longest palindromic substring, O(n^2) time complexity with dynamic programming