Cod sursa(job #2537634)

Utilizator RaduXD1Nicolae Radu RaduXD1 Data 3 februarie 2020 20:18:55
Problema PalM Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.71 kb
#include<bits/stdc++.h>
//#define fin cin
//#define fout cout
using namespace std;
ifstream fin("palm.in");
ofstream fout("palm.out");
int n,i,j,h,ok,sol,d[510][510][27];
char s[510];
int main()
{
    fin>>s+1;
    n=strlen(s+1);
    for(i=1;i<=n;i++)
        for(j=n;j>=i;j--)
        {
            for(h=0;h<='z'-'a';h++) d[i][j][h]=max(d[i][j+1][h],d[i-1][j][h]);
            if(s[i]==s[j])
            {
                if(i==j) ok=1; else ok=2;
                for(h=0;h<=s[i]-'a';h++)
                    d[i][j][s[i]-'a']=max(d[i][j][s[i]-'a'],d[i-1][j+1][h]+ok);
            }
            for(h=0;h<='z'-'a';h++) sol=max(sol,d[i][j][h]);
        }
    fout<<sol;
    //fout<<sol;
    return 0;
}