HDU - 4632
找出所有的子序列当中有多少是回文串
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 1010, INF = 1<<30, mod=10007;
int dp[N][N];
char s[N];
int main()
{
int T;scanf("%d",&T);for(int t=1;t<=T;t++){
memset(dp,0,sizeof dp);scanf("%s",s);int len=strlen(s);for(int i=0;i<len;i++) dp[i][i]=1;for(int i=1;i<len;i++)for(int j=i-1;j>=0;j--){
dp[j][i]=(dp[j+1][i]+dp[j][i-1]-dp[j+1][i-1])%mod;if(s[i]==s[j]) dp[j][i]=(dp[j][i]+dp[j+1][i-1]+1)%mod;}printf("Case %d: %d\n",t,(dp[0][len-1]+mod)%mod);}return 0;
}