记录路径的lcs
ACcode:
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#define maxn 101
#define inf 0x3f3f3f3f
#define ll long long
using namespace std;
struct N{
char s[33];
};
N a[maxn],b[maxn];
char tmp[33];
int lena,lenb,lenans;
int dp[maxn][maxn];
struct NN{
int num[maxn];
int tot;
}ans[maxn][maxn];
int main(){
while(scanf("%s",tmp)!=EOF){
lena=lenb=1;
strcpy(a[lena++].s,tmp);
memset(dp,0,sizeof(dp));
memset(ans,0,sizeof(ans));
while(scanf("%s",a[lena].s)&&a[lena++].s[0]!='#');
while(scanf("%s",b[lenb].s)&&b[lenb++].s[0]!='#');
for(int i=1;i<lena;++i)
for(int j=1;j<lenb;++j){
if(strcmp(a[i].s,b[j].s)==0){
dp[i][j]=dp[i-1][j-1]+1;
for(int k=0;k<ans[i-1][j-1].tot;++k)
ans[i][j].num[k]=ans[i-1][j-1].num[k];
ans[i][j].tot=ans[i-1][j-1].tot;
ans[i][j].num[ans[i][j].tot++]=i;
}
else {
if(dp[i-1][j]>dp[i][j-1]){
dp[i][j]=dp[i-1][j];
for(int k=0;k<ans[i-1][j].tot;++k)
ans[i][j].num[k]=ans[i-1][j].num[k];
ans[i][j].tot=ans[i-1][j].tot;
}
else {
dp[i][j]=dp[i][j-1];
for(int k=0;k<ans[i][j-1].tot;++k)
ans[i][j].num[k]=ans[i][j-1].num[k];
ans[i][j].tot=ans[i][j-1].tot;
}
}
}
//cout<<dp[lena-1][lenb-1]<<'\12';
for(int i=0;i<ans[lena-1][lenb-1].tot-1;++i,putchar(' '))
printf("%s",a[ans[lena-1][lenb-1].num[i]].s);
putchar('\n');
}
return 0;
}