fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. string **dp;
  7. int main() {
  8. string s1,s2;
  9. long long i,j;
  10. cin>>s1;
  11. s2=s1;
  12. long long m=s1.size()+1;
  13. reverse(s2.begin(),s2.end());
  14. dp=new string* [m];
  15. for(i=0;i<m;i++)dp[i]=new string [m];
  16. for(i=1;i<m;i++){
  17. for(j=1;j<m;j++){
  18. if(s1[i-1]==s2[j-1])dp[i][j]=dp[i-1][j-1]+s2[j-1];
  19. else{
  20. if(dp[i-1][j].size()>dp[i][j-1].size())dp[i][j]=dp[i-1][j];
  21. else dp[i][j]=dp[i][j-1];
  22. }
  23. }
  24. }
  25. cout<<dp[m-1][m-1];
  26. return 0;
  27. }
Success #stdin #stdout 0s 15240KB
stdin
babaob
stdout
babab