Advertisement
Guest User

Untitled

a guest
May 25th, 2015
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #include<cstdio>
  2. #include<sstream>
  3. #include<cstdlib>
  4. #include<cctype>
  5. #include<cmath>
  6. #include<algorithm>
  7. #include<set>
  8. #include<queue>
  9. #include<stack>
  10. #include<list>
  11. #include<iostream>
  12. #include<fstream>
  13. #include<numeric>
  14. #include<string>
  15. #include<vector>
  16. #include<cstring>
  17. #include<map>
  18. #include<iterator>
  19. using namespace std;
  20. char s[5010];
  21. int n,dp[5010][5010];
  22.  
  23. int count(int i,int n)
  24. {
  25. if(dp[i][n]!=-1)
  26. return dp[i][n];
  27. if(i>=n)
  28. return 0;
  29. if(s[i]==s[n])
  30. return dp[i][n]=count(i+1,n-1);
  31. else
  32. return dp[i][n]=min(count (i+1,n)+1,count(i,n-1)+1);
  33. }
  34. int main()
  35. {
  36. memset(dp,-1,sizeof dp);
  37.  
  38. cin >> n;
  39. getchar();
  40. gets(s);
  41. int i=count(0,n-1);
  42. cout << i << "\n" ;
  43. return 0;
  44.  
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement