Cod sursa(job #2750604)

Utilizator tomaionutIDorando tomaionut Data 12 mai 2021 10:49:08
Problema PalM Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <bits/stdc++.h>

using namespace std;
ifstream fin("palm.in");
ofstream fout("palm.out");
char s[505],ch;
int dp[505][505],sol;
int main()
{
    int n,i,j,d;
    fin >> s+1;
    n=strlen(s+1);
    for (ch='z'; ch>='a'; ch--)
    {
        for (d=2; d<=n; d++)
        {
            for (i=1; i+d-1<=n; i++)
            {
                j=i+d-1;
                if (s[i]==ch)
                {
                dp[i][i]=1;
                if (s[i]==s[j]) dp[i][j]=max(dp[i+1][j-1]+2,dp[i][j]);
                }
                dp[i][j]=max({dp[i+1][j],dp[i][j-1],dp[i][j]});
                sol=max(sol,dp[i][j]);
            }
        }
    }
    fout << sol;


    return 0;
}