标签:字符串
#include <set>
#include <map>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; // soj 4421 //problems
typedef long long int LL;
const int M = 1009,INF = 0x3fffffff;
char a[M], b[M];
int main(void) {
while(~scanf("%s%*c", a)) {
int n = strlen(a);
for(int i = 0; i < n; i++) b[i] = a[n - i - 1];
int dp[n + 1][n + 1];
memset(dp, 0, sizeof(dp));
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
if(a[i - 1] == b[j - 1]) dp[i][j] = dp[i - 1][j - 1] + 1;
else dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
printf("%d\n", dp[n][n]);
}
return 0;
}
标签:字符串
原文地址:http://blog.csdn.net/jibancanyang/article/details/45788071