Cod sursa(job #2537886)

Utilizator AlexPascu007Pascu Ionut Alexandru AlexPascu007 Data 4 februarie 2020 07:54:00
Problema PalM Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.66 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin("palm.in");
ofstream fout("palm.out");
int n,i,j,lg,d[510][510],sol;
char s[510],c;
int main() {
    fin>>(s+1);
    n=strlen(s+1);
    for (c='z';c>='a';c--) {
        for (lg=2;lg<=n;lg++) {
            for (i=1;i+lg-1<=n;i++) {
                j=i+lg-1;
                if (s[i]==c) {
                    d[i][i]=1;
                    if (s[i]==s[j])
                        d[i][j]=max(d[i][j],2+d[i+1][j-1]);
                }
                d[i][j]=max(d[i][j],max(d[i+1][j],d[i][j-1]));
                sol=max(sol,d[i][j]);
            }
        }
    }
    fout<<sol;
    return 0;
}