Pagini recente » Cod sursa (job #1996118) | Cod sursa (job #2718442) | Cod sursa (job #2054029) | Monitorul de evaluare | Cod sursa (job #2538519)
#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;
}