Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3595 Accepted Submission(s): 1857
Special Judge
#include <iostream> #include <algorithm> #include <cstring> #include <cstdio> #include <vector> #include <iomanip> #include <cmath> #include <ctime> #include <map> #include <set> using namespace std; #define lowbit(x) (x&(-x)) #define max(x,y) (x>y?x:y) #define min(x,y) (x<y?x:y) #define MAX 100000000000000000 #define MOD 1000000007 #define pi acos(-1.0) #define ei exp(1) #define PI 3.141592653589793238462 #define INF 0x3f3f3f3f3f #define mem(a) (memset(a,0,sizeof(a))) typedef long long ll; int dp[105][105],i,j; char a[105],b[105]; int main() { while(scanf("%s %s",&a,&b)!=EOF) { int la=strlen(a); int lb=strlen(b); memset(dp,0,sizeof(dp)); for(i=1;i<=la;i++) { for(j=1;j<=lb;j++) { if(a[i-1]==b[j-1]) dp[i][j]=dp[i-1][j-1]+1; else dp[i][j]=max(dp[i-1][j],dp[i][j-1]); } } string s=""; while(i>0 && j>0) { if(a[i-1]==b[j-1]) s+=a[i-1],i--,j--; else if(dp[i-1][j]>dp[i][j-1]) s+=a[i-1],i--; else s+=b[j-1],j--; } while(i>0) s+=a[i-1],i--; while(j>0) s+=b[j-1],j--; reverse(s.begin(),s.end()); cout<<s<<endl; memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); } return 0; }
原文:http://www.cnblogs.com/shinianhuanniyijuhaojiubujian/p/7230885.html