Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- typedef pair<ll,ll> pll;
- #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL))
- #define fi first
- #define se second
- #define pb push_back
- ll const MOD=1000000007;
- const int M= 1e5 +10;
- #define eb emplace_back
- ll ara[100][100];
- string a,b;
- void lcs(int n, int m )
- {
- for(ll i=1;i<=n;i++)
- {
- for(ll j=1;j<=m;j++)
- {
- if(a[i]==b[i])ara[i][j]=1+ara[i-1][j-1];
- else ara[i][j]=max(ara[i-1][j],ara[i][j-1]);
- }
- }
- cout<<ara[n][m]<<endl;
- int i=n, j=m;
- while (i > 0 && j > 0)
- {
- cout<<i<<" "<<j<<endl;
- cout<<a[i-1]<<" "<<b[j-1]<<endl;
- if(a[i-1]==b[j-1])
- {
- cout<<a[i-1]<<endl;;
- i--; j--;
- }
- else if (ara[i-1][j] > ara[i][j-1]) i--;
- else
- j--;
- }
- }
- int main()
- {
- cin>>a>>b;
- ll n=a.size();
- ll m=b.size();
- lcs(n,m);
- }
Add Comment
Please, Sign In to add comment