Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <algorithm>
- #include <cstring>
- #include <string>
- #include <cctype>
- #include <stack>
- #include <queue>
- #include <list>
- #include <vector>
- #include <map>
- #include <set>
- #include <sstream>
- #include <limits.h>
- #include <stdlib.h>
- #include <cmath>
- #define LL unsigned long long
- using namespace std;
- int lcs[1010][1010];
- int main() {
- char x[1010];char y[1010];
- int n1,n2;
- while(gets(x)){
- gets(y);
- n1=strlen(x);n2=strlen(y);
- for(int i=1;i<=n1;i++){
- for(int j=1;j<=n2;j++){
- if(x[i-1]==y[j-1]){
- lcs[i][j]=1+lcs[i-1][j-1];
- }else{
- lcs[i][j]=max(lcs[i-1][j],lcs[i][j-1]);
- }
- }
- }
- printf("%d\n",lcs[n1][n2]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement