Cod sursa(job #636380)

Utilizator SpiderManSimoiu Robert SpiderMan Data 19 noiembrie 2011 19:29:16
Problema PalM Scor 20
Compilator cpp Status done
Runda .com 2011 Marime 1.11 kb
# 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;
}