Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const short NMAX=201;
- char a[NMAX],b[NMAX];
- int n,m,dp[NMAX][NMAX];
- ifstream fin("codul.in");
- ofstream fout("codul.out");
- int main()
- {
- fin>>(a+1)>>(b+1);
- n=strlen(a+1);
- m=strlen(b+1);
- for(int i=n; i>=1; i--)
- for(int j=m; j>=1; j--)
- if(a[i]==b[j])
- dp[i][j]=1+dp[i+1][j+1];
- else dp[i][j]=max(dp[i+1][j],dp[i][j+1]);
- int xi,xj,pi,pj,mx;
- mx=dp[1][1];
- xi=xj=0;
- while(mx)
- {
- char ch='0';
- for(int i=xi+1; i<=n; i++)
- for(int j=xj+1; j<=m; j++)
- if(a[i]==b[j] && dp[i][j]==mx && ch<a[i])
- {
- ch=a[i];
- pi=i;
- pj=j;
- }
- xi=pi;
- xj=pj;
- fout<<ch;
- mx--;
- }
- fin.close();
- fout.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment