Advertisement
juanjo12x

UVA_10192_Vacation

Aug 6th, 2014
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 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[110][110];
  20. int main() {
  21.     int n1,n2;
  22.     char x[110];char y[110];
  23.     int cont=1;
  24.     while(gets(x)){
  25.         if(strcmp(x,"#")==0) break;
  26.         gets(y);
  27.         n1=strlen(x);n2=strlen(y);
  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("Case #%d: you can visit at most %d cities.\n",cont,lcs[n1][n2]);
  38.         cont++;
  39.          
  40.     }
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement