LCS with three strings

two test cases are not being passed…what is it i m doing wrong …plz tell.

int main() {
string s1;
string s2;
string s3;
cin>>s1;
cin>>s2;
cin>>s3;

int n=s1.size();
int m=s2.size();
int l=s2.size();
int dp[n+1][m+1][l+1];
memset(dp,0,sizeof(dp));



for(int i=1;i<n+1;i++){
    for(int j=1;j<m+1;j++){
        for(int k=1;k<l+1;k++){
            if(s1[i-1]==s2[j-1]&&s2[j-1]==s3[k-1]){
                dp[i][j][k]=1+dp[i-1][j-1][k-1];
            }
            else{
                dp[i][j][k]=max(dp[i-1][j][k],max(dp[i][j-1][k],dp[i][j][k-1]));
            }
        }
    }
}
cout<<dp[n][m][l];

return 0;

}

Hi
Pls paste your code in coding blocks ide , then pass on the link

1 Like


last test case shows wrong ans. plzz check