Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int dp[2001][2001];
- int main()
- {
- string a;
- cin>>a;
- int l=a.size();
- for(int i=0;i<=l;i++){
- for(int j=0;j<=l;j++){
- if(i==0 || j==0) dp[i][j]=0;
- else if(a[i-1]==a[j-1] && i!= j) dp[i][j]=1+dp[i-1][j-1];
- else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
- }
- }
- printf("%d",dp[l][l]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement