Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- string a,b,ans;
- int dp[2020][2020];
- void find(int n,int m){
- int mx=0,st,en;
- for(int i=0;i<=n;i++){
- for(int j=0;j<=m;j++){
- if(i==0||j==0){dp[i][j]=0;}
- else if(a[i-1]==b[j-1]){
- dp[i][j]=1+dp[i-1][j-1];
- if(mx<dp[i][j]){
- mx=dp[i][j];
- st=i; en=j;
- }
- }
- else{dp[i][j]=0;}
- }
- }
- while(dp[st][en]!=0){
- ans=a[st-1]+ans; st--;en--;
- }
- cout<<ans;
- return;
- }
- int main(){
- cin>>a; cin>>b;
- find(a.size(),b.size());
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement