tanasaradu

Untitled

Dec 5th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const short NMAX=201;
  4. char a[NMAX],b[NMAX];
  5. int n,m,dp[NMAX][NMAX];
  6. ifstream fin("codul.in");
  7. ofstream fout("codul.out");
  8. int main()
  9. {
  10. fin>>(a+1)>>(b+1);
  11. n=strlen(a+1);
  12. m=strlen(b+1);
  13. for(int i=n; i>=1; i--)
  14. for(int j=m; j>=1; j--)
  15. if(a[i]==b[j])
  16. dp[i][j]=1+dp[i+1][j+1];
  17. else dp[i][j]=max(dp[i+1][j],dp[i][j+1]);
  18. int xi,xj,pi,pj,mx;
  19. mx=dp[1][1];
  20. xi=xj=0;
  21. while(mx)
  22. {
  23. char ch='0';
  24. for(int i=xi+1; i<=n; i++)
  25. for(int j=xj+1; j<=m; j++)
  26. if(a[i]==b[j] && dp[i][j]==mx && ch<a[i])
  27. {
  28. ch=a[i];
  29. pi=i;
  30. pj=j;
  31. }
  32.  
  33. xi=pi;
  34. xj=pj;
  35. fout<<ch;
  36. mx--;
  37. }
  38. fin.close();
  39. fout.close();
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment