Advertisement
SuitNdtie

MagicSpell3

May 15th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3. char str[2010];
  4.  
  5. int max(int a,int b){
  6.     return (a > b ? a : b);
  7. }
  8.  
  9. int dp[2010][2010];
  10.  
  11. int cal(int i,int j){
  12.     if(i < 0 || j < 0)return 0;
  13.     if(dp[i][j] != -1)return dp[i][j];
  14.     if(str[i] == str[j] && i != j){
  15.         return cal(i-1,j-1) + 1;
  16.     }
  17.     return dp[i][j] = max(cal(i-1,j),cal(i,j-1));
  18. }
  19.  
  20. int main()
  21. {
  22.     for(int i = 0 ; i < 2010 ; i ++)for(int j = 0 ; j < 2010 ; j ++)dp[i][j] = -1;
  23.     scanf("%s",str);
  24.     int n = strlen(str);
  25.     printf("%d",cal(n-1,n-1));
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement