Cod sursa(job #2537872)
Utilizator | Danut Aldea DanutAldea | Data | 4 februarie 2020 01:17:29 |
---|---|---|---|
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");
char c[510],x;
int n,i,j,lung,d[510][510],sol;
int main(){
fin>>c+1;
n=strlen(c+1);
for(x='z';x>='a';x--){
for(lung=2;lung<=n;lung++){
for(i=1;i+lung-1<=n;i++){
j=i+lung-1;
if(c[i]==x){
d[i][i]=1;
if(c[i]==c[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(d[i][j],sol);
}
}
}
fout<<sol;
return 0;
}