Advertisement
juanjo12x

UVA_10405_LCS

Aug 6th, 2014
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4. #include <cstring>
  5. #include <string>
  6. #include <cctype>
  7. #include <stack>
  8. #include <queue>
  9. #include <list>
  10. #include <vector>
  11. #include <map>
  12. #include <set>
  13. #include <sstream>
  14. #include <limits.h>
  15. #include <stdlib.h>
  16. #include <cmath>
  17. #define LL unsigned long long
  18. using namespace std;
  19. int lcs[1010][1010];
  20. int main() {
  21.     char x[1010];char y[1010];
  22.    
  23.     int n1,n2;
  24.     while(gets(x)){
  25.         gets(y);
  26.         n1=strlen(x);n2=strlen(y);
  27.        
  28.         for(int i=1;i<=n1;i++){
  29.             for(int j=1;j<=n2;j++){
  30.                 if(x[i-1]==y[j-1]){
  31.                    lcs[i][j]=1+lcs[i-1][j-1];
  32.                 }else{
  33.                     lcs[i][j]=max(lcs[i-1][j],lcs[i][j-1]);
  34.                 }
  35.             }
  36.         }
  37.         printf("%d\n",lcs[n1][n2]);
  38.     }
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement