Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define pb push_back
- #define f first
- #define s second
- #define all(c) c.begin(),c.end()
- using namespace std;
- typedef long long ll;
- const ll INF64 = 1e18 + 1337;
- const int INF32 = 1e9 + 228;
- const int MOD = 1e9 + 7;
- int main()
- {
- ios_base::sync_with_stdio(0);
- #ifndef __WIN32
- ifstream cin("input.txt");
- ofstream cout("output.txt");
- #endif
- cin.tie(0);cout.tie(0);
- int buf;
- cin >> buf;
- string s;
- cin >> s;
- int n = s.length();
- vector< vector<string> > dp(n, vector<string>(n, ""));
- for(int i = 0; i < n; i++) dp[i][i].pb(s[i]);
- for(int r = 0; r < n; r++)
- {
- for(int l = r - 1; l >= 0; l--)
- {
- if(s[l] == s[r])
- dp[l][r] = s[l] + dp[l + 1][r - 1] + s[r];
- else
- {
- if(dp[l][r - 1].length() > dp[l + 1][r].length())
- dp[l][r] = dp[l][r - 1];
- else dp[l][r] = dp[l + 1][r];
- }
- }
- }
- cout << dp[0][n - 1];
- #ifndef __WIN32
- cin.close();
- cout.close();
- #endif
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement