Cod sursa(job #2720187)

Utilizator PredescuSebastianIonPredescu Sebastian Ion PredescuSebastianIon Data 10 martie 2021 17:26:17
Problema PalM Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <bits/stdc++.h>

using namespace std;
ifstream f("palm.in");
ofstream g("palm.out");
int n,sol,a[510][510];
char s[510];
int main()
{
    f>>s+1;
    n=strlen(s+1);
    for(char ch='z'; ch>='a'; ch--)
    {
        for(int dim=2; dim<=n; dim++)
        {
            for(int i=1; i<=n-dim+1; i++)
            {
                int j=i+dim-1;
                if(s[i]==ch)
                {
                    a[i][i]=1;
                    if(s[i]==s[j])a[i][j]=max(a[i][j],2+a[i+1][j-1]);
                }
                a[i][j]=max(a[i][j],max(a[i+1][j],a[i][j-1]));
                sol=max(sol,a[i][j]);
            }
        }
    }
    g<<sol<<'\n';
    return 0;
}