标签:dp
4 a aaaaa goodafternooneveryone welcometoooxxourproblems
Case 1: 1 Case 2: 31 Case 3: 421 Case 4: 960#include<stdio.h> #include<string.h> int t,dp[1005][1005],c=0; int main() { char str[1005]; scanf("%d",&t); while(t--) { scanf("%s",str); int len=strlen(str); memset(dp,0,sizeof(dp)); for(int i=0;i<len;i++) dp[i][i]=1; for(int r=1;r<len;r++) for(int i=0;i<len-r;i++) { int j=i+r; dp[i][j]=(dp[i+1][j]+dp[i][j-1]-dp[i+1][j-1]+10007)%10007; if(str[i]==str[j]) dp[i][j]=(dp[i][j]+dp[i+1][j-1]+1)%10007; } printf("Case %d: %d\n",++c,dp[0][len-1]); } }
hdu4632Palindrome subsequence (求回文数,区间DP)
标签:dp
原文地址:http://blog.csdn.net/u010372095/article/details/38010169