uva 11404

来源:互联网 发布:中小企业网络解决方案 编辑:程序博客网 时间:2024/06/10 08:56
#include<cstdio>#include<cstring>#include<string>#include<iostream> using namespace std;struct node{int v;string s;bool operator>(const node &a)const{if(v==a.v)return s<a.s;elsereturn v>a.v;}}dp[1010][1010];char str[1010];int main(){while(~scanf("%s",str+1)){int len=strlen(str+1);for(int i=len;i>=1;i--)for(int j=i;j<=len;j++){if(str[i]==str[j]){if(i==j){dp[i][j].v=1;dp[i][j].s=str[i];}else{dp[i][j].v=dp[i+1][j-1].v+2;dp[i][j].s=str[i]+dp[i+1][j-1].s+str[j];}}else{if(dp[i+1][j]>dp[i][j-1]){dp[i][j].v=dp[i+1][j].v;dp[i][j].s=dp[i+1][j].s;}else {   dp[i][j].v=dp[i][j-1].v;   dp[i][j].s=dp[i][j-1].s;}}}cout<<dp[1][len].s<<endl;} }

原创粉丝点击