Advertisement
Brick99

IOI 00 Palindrome

May 26th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <cmath>
  4. #include <algorithm>
  5. #include <vector>
  6. #include <iomanip>
  7. #include <stack>
  8. #include <queue>
  9. #include <set>
  10. #include <utility>
  11.  
  12. using namespace std;
  13.  
  14. int main()
  15. {
  16.     int n;
  17.     cin>>n;
  18.     string g;
  19.     cin>>g;
  20.  
  21.     int dp[2][n+1];
  22.     for (int i=0;i<2;i++)
  23.         for (int j=0;j<=n;j++)
  24.             dp[i][j]=0;
  25.  
  26.     for (int i=1;i<=n;i++)
  27.         for (int j=1;j<=n;j++)
  28.             if ( g[i-1] == g[n-j] ) dp[i%2][j]=dp[(i-1)%2][j-1]+1;
  29.             else dp[i%2][j]=max(dp[(i-1)%2][j],dp[i%2][j-1]);
  30.  
  31.     cout<<n-dp[n%2][n]<<endl;
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement