Skip to content

Instantly share code, notes, and snippets.

@vlw
Created January 8, 2018 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vlw/3a9282746feca2590b5bf6137b10865e to your computer and use it in GitHub Desktop.
Save vlw/3a9282746feca2590b5bf6137b10865e to your computer and use it in GitHub Desktop.
Lol.k
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string **dp;
int main() {
string s1,s2;
long long i,j;
cin>>s1;
s2=s1;
long long m=s1.size()+1;
reverse(s2.begin(),s2.end());
dp=new string* [m];
for(i=0;i<m;i++)dp[i]=new string [m];
for(i=1;i<m;i++){
for(j=1;j<m;j++){
if(s1[i-1]==s2[j-1])dp[i][j]=dp[i-1][j-1]+s2[j-1];
else{
if(dp[i-1][j].size()>dp[i][j-1].size())dp[i][j]=dp[i-1][j];
else dp[i][j]=dp[i][j-1];
}
}
}
cout<<dp[m-1][m-1];
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment