记录编号 | 400744 | 评测结果 | AAAAAAAAAA | ||
---|---|---|---|---|---|
题目名称 | 最长公共子序列 | 最终得分 | 100 | ||
用户昵称 | 是否通过 | 通过 | |||
代码语言 | C++ | 运行时间 | 0.604 s | ||
提交时间 | 2017-04-30 20:50:53 | 内存使用 | 95.89 MiB | ||
#include <iostream> #include <cstdio> #include <fstream> #include <algorithm> #include <cmath> #include <deque> #include <vector> #include <queue> #include <string> #include <cstring> #include <map> #include <stack> #include <set> #define ghb great handsome boy; using namespace std; typedef long long ll; typedef int itn; const int max_n=5005; char a[max_n],b[max_n],c[max_n],d[max_n]; int dp[max_n][max_n]; int main() { freopen("lcslength.in","r",stdin); freopen("lcslength.out","w",stdout); scanf("%s%s",a,b); int lena=strlen(a); int lenb=strlen(b); for(itn i=0;i<lena;i++) if(a[i]!='.') c[i+1]=a[i]; for(int i=0;i<lenb;i++) if(b[i]!='.')d[i+1]=b[i]; for(int i=1;i<lena;i++) for(int j=1;j<lenb;j++) { if(c[i]==d[j])dp[i][j]=max(dp[i][j],dp[i-1][j-1]+1); else dp[i][j]=max(dp[i][j-1],dp[i-1][j]); } int maxn=-100; for(int i=1;i<lena;i++) for(int j=1;j<lenb;j++) maxn=max(maxn,dp[i][j]); cout<<maxn; fclose(stdin); fclose(stdout); return 0; }