Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int lcs(string a,string b,int c,int d)
- {
- int len[c+5][d+5];
- for (int i = 0; i <= c; i++)
- {
- for (int j = 0; j<= d; j++)
- {
- if (i==0 || j==0)
- len[i][j] = 0;
- else if (a[i-1] == b[j-1])
- len[i][j]=1 + len[i-1][j-1];
- else
- len[i][j]=max(len[i-1][j],len[i][j-1]);
- }
- }
- return len[c][d];
- }
- int main()
- {
- string a,b;
- int c,d;
- cin>>a>>b;
- c=a.size();
- d=b.size();
- cout<<lcs(a,b,c,d)<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement