Problem with my code, cb ide is not working so i am just pasting it directly

#include<bits/stdc++.h>
using namespace std;
void lcs(string s1, string s2){
int n=s1.length();
int m=s2.length();
int dp[n+1][m+1];
for(int i=0;i<=n;i++){
for(int j=0;j<=m;j++){
dp[i][j]=0;
}
}
for(int i=n-1;i>=0;iā€“){
for(int j=m-1;j>=0;jā€“){
if(s1[i]==s2[j]){
dp[i][j]=1+dp[i+1][j+1];
}
else{
int op1=dp[i+1][j];
int op2=dp[i][j+1];
dp[i][j]=max(op1,op2);
}
}
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(dp[i][j]-dp[i+1][j]==1 && dp[i][j]-dp[i][j+1]==1){
if(s1[i]==s2[j])
cout<<s1[i];
}
}
}

}
int main() {
string s1;
string s2;
cin>>s1>>s2;
lcs(s1,s2);
return 0;
}

hello @Parmeet-Kalsi-1631789033630118 i am going through your code please wait for some time i will let you know what you are doing wrong .

ok fine,
just neglect the s[i]==s[j] condition in the printing loop i just put it for checcking

hey @Parmeet-Kalsi-1631789033630118 as your code was not working .
you code is not even compiling thats why i have rewriiten your logic completely and it took time for me to reply .


corrected code above
if you feel that your doubt is cleared please mark this doubt as resolved .
Happy Learning !!

yes it is clear , thanks a lot.
can you please tell me the benefit of using vector for dp in place of normal array.

@Parmeet-Kalsi-1631789033630118 the benefit is this that vector is self adjusting in terms of size .
moreover it is just about practice once you will also do major dp questions you will also be in habbit of using vector only .
if you still have anhy doubt please do ask here
Happy Learning !!