
当s[i] = s[j] dp[i][j] = 1+dp[i+1][j-1]+dp[i+1][j]+dp[i][j-1]-dp[i+1][j-1] = 1+dp[i][j-1]+dp[i+1][j]
当s[i] != s[j] dp[i][j] = dp[i+1][j]+dp[i][j-1]-dp[i+1][j-1]
答案超int
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <sstream>
#include <string>
#include <cstring>
#include <algorithm>
#include <iostream>
#define maxn 100
#define INF 0x7fffffff
#define inf 10000000
#define ull unsigned long long
#define ll long long
using namespace std; ll dp[maxn][maxn];
char s[maxn]; void solve(int n)
{
memset(dp, 0, sizeof(dp));
for(int i = 0; i < n; ++ i) dp[i][i] = 1;
for(int i = n-2; i >= 0; -- i)
for(int j = i+1; j < n; ++ j)
{
if(s[i] == s[j]) dp[i][j] = 1 + dp[i][j-1] + dp[i+1][j];
else dp[i][j] = dp[i+1][j] + dp[i][j-1] - dp[i+1][j-1];
}
} int main()
{
int t, n;
scanf("%d", &t);
while(t --)
{
scanf("%s", s);
solve(n = strlen(s));
printf("%lld\n", dp[0][n-1]);
}
return 0;
}