Pagini recente » Cod sursa (job #3133969) | Cod sursa (job #1429564) | Cod sursa (job #2482433) | Cod sursa (job #2584583) | Cod sursa (job #636385)
Cod sursa(job #636385)
# 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;
// && v[i] < v[i + 1] && v[j] > v[j - 1]
if (v[i]==v[j]&& v[i] < v[i + 1] && v[j] < v[j - 1]) {
//printf ("%c < %c %c > %c\n", v[i], v[i + 1], v[j], v[j - 1]);
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;
}