Cod sursa(job #2538520)

Utilizator MihneaGhiraMihnea MihneaGhira Data 4 februarie 2020 20:14:34
Problema PalM Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.69 kb
#include<fstream>
#include<cstring>
using namespace std;
ifstream fin("palm.in");
ofstream fout("palm.out");
int n,nr;
int D[510][510];
char s[510];
int main(){
    fin>>s;
    n=strlen(s);
    for(char c='z';c>='a';c--){
        for(int k=2;k<=n;k++){
            for(int i=0;i+k-1<n;i++){
                int j=i+k-1;
                if(s[i]==c){
                    D[i][i]=1;
                    if(s[i]==s[j]){
                        D[i][j]=max(D[i][j],D[i+1][j-1]+2);
                    }
                }
                D[i][j]=max(D[i][j], max(D[i][j-1],D[i+1][j]) );
                nr=max(nr,D[i][j]);
            }
        }
    }
    fout<<nr;
    return 0;
}