您的位置:首页 > 大数据 > 人工智能

Uva 10617 Again Palindromes

2013-08-23 21:12 363 查看
CLICK ME

问一个字符串的子序列是回文串的个数;

dp

#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;

char s[70];
long long dp[70][70];

int main() {
int cas;
//freopen("input.txt","r",stdin);
scanf("%d",&cas);
while(cas--){
scanf("%s",s+1);
int n=strlen(s+1);
memset(dp,0,sizeof dp);
for(int k=0;k<n;k++) {
for(int l=1;l<=n;l++) {
int r=l+k;if(r>n) break;
if(s[l]!=s[r]) {
dp[l][r] = dp[l+1][r]+dp[l][r-1]-dp[l+1][r-1];
}else {
dp[l][r] = dp[l+1][r]+dp[l][r-1];
dp[l][r] ++;
}
}
}
//printf("%d\n",dp[1]
);
cout<<dp[1]
<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: