int longestCommonSubsequence(string text1, string text2) {
//dp[i][j]记录text1前i序列和text2前j序列的最长公共序列
int dp[1005][1005];
memset(dp,0,sizeof(dp));
for(int i=1;i<=text1.size();i++){
for(int j=1;j<=text2.size();j++){
dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
if(text1[i-1]==text2[j-1]){
dp[i][j]=max(dp[i][j],dp[i-1][j-1]+1);
}
}
}
return dp[text1.size()][text2.size()];
}
标签:string,int,text2,text1,序列,LC1143,最长,dp
From: https://www.cnblogs.com/lwx11111/p/16715358.html