编写一个程序来查找给定字符串中最长的回文子串。
字符串示例：babad
以下是使用动态规划算法的 Python 代码实现：

```python
def longest_palindrome(s: str) -> str:
    n = len(s)
    # dp[i][j]: whether s[i:j+1] is palindrome or not
    dp = [[False] * n for _ in range(n)]
    max_len = 0
    start = end = 0
    
    # all substrings of length 1 are palindromes
    for i in range(n):
        dp[i][i] = True
    
    # check substrings of length 2
    for i in range(n-1):
        if s[i] == s[i+1]:
            dp[i][i+1] = True
            max_len = 2
            start = i
            end = i+1
    
    # check substrings of length >= 3
    for l in range(3, n+1):
        for i in range(n-l+1):
            j = i+l-1
            if s[i] == s[j] and dp[i+1][j-1]:
                dp[i][j] = True
                if l > max_len:
                    max_len = l
                    start = i
                    end = j
    
    return s[start:end+1]
```

例如，对于字符串 `babad`，以上代码返回结果为 `bab`。