算法导论提到过这题
class Solution { public: int longestCommonSubsequence(string text1, string text2) { int a[1001][1001]; int i,j; for(i=0;i<1001;i++){ a[i][0]=0; a[0][i]=0; } for(i=1;i<=text1.length();i++){ for(j=1;j<=text2.length();j++){ if(text1[i-1]==text2[j-1]){ a[i][j]=a[i-1][j-1]+1; }else{ a[i][j]=max(a[i-1][j],a[i][j-1]); } } } return a[text1.length()][text2.length()]; } };
原文:https://www.cnblogs.com/hyffff/p/14619871.html