标签:dp
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdlib>
using namespace std;
typedef long long ll;
char s[100];
ll dp[100][100];
int main() {
int T;
scanf("%d", &T);
while (T--) {
scanf("%s", s);
int len = strlen(s);
for (int i = 0; i < len; i++) {
dp[i][i] = 1;
}
for (int i = len - 2; i >= 0; i--) {
for (int j = i + 1; j < len; j++) {
if (s[i] == s[j]) {
dp[i][j] = dp[i + 1][j] + dp[i][j - 1] + 1;
} else {
dp[i][j] = dp[i + 1][j] + dp[i][j - 1] - dp[i + 1][j - 1];
}
}
}
printf("%lld\n", dp[0][len - 1]);
}
return 0;
}
uva 10617 Again Palindrome (DP)
标签:dp
原文地址:http://blog.csdn.net/llx523113241/article/details/44946985