516. 最长回文子序列
C代码:dp
int longestPalindromeSubseq(char* s) {
int n = strlen(s);
int dp[n][n];
memset(dp, 0, sizeof(dp));
for (int i = 0; i < n; i++) {
dp[i][i] = 1;
}
for (int i = n - 1; i >= 0; i--) {
for (int j = i + 1; j < n; j++) {
if (s[i] == s[j]) {
dp[i][j] = dp[i + 1][j - 1] + 2;
} else {
dp[i][j] = fmax(dp[i + 1][j], dp[i][j - 1]);
}
}
}
return dp[0][n - 1];