标签:最长公共子序列 iostream define sizeof namespace using set 线性 sequence
#include <iostream> #include <algorithm> #include <string> #include <cstring> #include <cstdio> #define MAX 1005 using namespace std; int ans[MAX][MAX]; int main(){ string s1,s2; while(cin>>s1>>s2) { memset(ans,0,sizeof ans); int len1=s1.size(); int len2=s2.size(); for(int i=1;i<=len1;i++) for(int j=1;j<=len2;j++){ if(s1[i-1]==s2[j-1]) ans[i][j]=ans[i-1][j-1]+1; else ans[i][j]=max(ans[i-1][j],ans[i][j-1]); } cout<<ans[len1][len2]<<endl; } return 0; }
Common Subsequence POJ - 1458 最长公共子序列 线性DP
标签:最长公共子序列 iostream define sizeof namespace using set 线性 sequence
原文地址:https://www.cnblogs.com/QingyuYYYYY/p/12238436.html