Pagini recente » Cod sursa (job #1265086) | Cod sursa (job #3031486) | Cod sursa (job #325689) | Cod sursa (job #1614383) | Cod sursa (job #636380)
Cod sursa(job #636380)
# include <cstdio>
# include <cstring>
#define MOD 666013
#define DIM 2005
int best[3][DIM];
char v[DIM];
int n;
void read () {
int i;
scanf ("%s", v + 1);
n = strlen (v + 1);
}
void solve () {
int i,j,lg;
for (i=1; i<=n; ++i)
best[0][i]=1;
for (i=1; i+1<=n; ++i)
if (v[i]==v[i+1]) {
best[1][i]=2;
} else {
best[1][i]=1;
}
for (lg=3; lg<=n; ++lg) {
for (i=1; i+lg-1<=n; ++i) {
j=i+lg-1;
best[2][i]=0;
if (v[i]==v[j]) {
best[2][i]=best[0][i+1]+2;
}
if (best[1][i]>best[2][i]) {
best[2][i]=best[1][i];
}
if (best[1][i+1]>best[2][i]) {
best[2][i]=best[1][i+1];
}
}
memcpy (best[0],best[1],sizeof (best[1]));
memcpy (best[1],best[2],sizeof (best[2]));
}
printf ("%d",best[2][1]);
}
int main () {
freopen ("palm.in","r",stdin);
freopen ("palm.out","w",stdout);
read ();
solve ();
return 0;
}