Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. ifstream fin("lungimesubsircomunmaximal.in");
  5. ofstream fout("lungimesubsircomunmaximal.out");
  6.  
  7. int n,m,LCS[1005][1005];
  8. char a[1005],b[1005];
  9. void pd()
  10. {
  11. for(int i=1;i<=n;i++)
  12. for(int j=1;j<=m;j++)
  13. if(a[i]==b[j])
  14. LCS[i][j]=1+LCS[i-1][j-1];
  15. else
  16. LCS[i][j]=max(LCS[i-1][j-1],max(LCS[i-1][j],LCS[i][j-1]));
  17.  
  18. fout<<LCS[n][m];
  19. }
  20.  
  21.  
  22. int main()
  23. {
  24. fin.getline(a+1,1005);
  25. fin.getline(b+1,1005);
  26.  
  27. n=strlen(a+1);
  28. m=strlen(b+1);
  29. pd();
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement