Cod sursa(job #637069)

Utilizator tzipleatudTudor Tiplea tzipleatud Data 20 noiembrie 2011 11:31:42
Problema PalM Scor 0
Compilator cpp Status done
Runda .com 2011 Marime 1.24 kb
#include <fstream>
#include <cstring>
using namespace std;

ifstream f("palm.in");
ofstream g("palm.out");

string s;
int i,n,v[501],sol=0,l[501][501],maxi,j;


int LCIS (int A,int B,int x) {
    int cr,l,i,j,ap=0,s;
    int c[501];
    memset(c,0,sizeof(c));
    for (i=1;i<=A;i++) {
        cr=0;
        if (v[i]==x) ap++;
        for (j=n;j>=B;j--) {
            if (v[i]==v[j] && cr+1>c[j])
                c[j]=cr+1;
            if (v[j]<v[i] && cr<c[j])
                cr=c[j];
            if (v[j]==x && i==1) ap++;
        }
    }
    l=0;int ind=-1;
    for (i=1;i<=n;i++)
        if (c[i]>l) {
            l=c[i];
            ind=i;
        }
    s=2*l;
    if (ap%2==0) s-=1;
        else s-=0;
    return s;
}

int main () {
    f >> s;
    n=s.size();
    for (i=1;i<=n;i++) v[i]=int(s[i-1])-int('a')+1;
    for (i=1;i<=n;i++) l[i][i]=1;
    for (j=1;j<=n;j++) {
        for (i=1;i<=n-j;i++) {
            if (v[i]==v[i+j]) {
                l[i][i+j]=l[i-1][i+j-1]+2;
            }
            else {
                l[i][i+j]=max(l[i+1][i+j],l[i][i+j-1]);
            }
            maxi=max(maxi,l[i][i+j]);
        }
    }
    g << maxi << '\n';
    f.close();g.close();
    return 0;
}