Cod sursa(job #2537888)

Utilizator radugheoRadu Mihai Gheorghe radugheo Data 4 februarie 2020 07:55:05
Problema PalM Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin  ("palm.in");
ofstream fout ("palm.out");

int n, l, i, j, sol;
int d[505][505];

char s[505], ch;

int main(){
    fin >> s + 1;
    n = strlen (s + 1);
    for (ch='z'; ch>='a'; ch--){
        for (l=2; l<=n; l++){
            for (i=1; i+l-1<=n; i++){
                j = i + l - 1;
                if (s[i] == ch){
                    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+1][j], d[i][j-1]));
                sol = max (sol, d[i][j]);
            }
        }
    }
    fout << sol;
    return 0;
}