Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <cstring>
- #include <map>
- using namespace std;
- const int maxn = 205;
- map<pair<char, char>, bool> compatible;
- int dp[maxn][maxn];
- string s;
- int rec(int i, int j) {
- if(j - i <= 1) {
- return 0;
- }
- if(dp[i][j] != -1) {
- return dp[i][j];
- }
- int res = 0;
- if(compatible[make_pair(s[i], s[j])]) {
- res = max(res, rec(i + 1, j - 1) + 1);
- }
- for(int k = i; k < j; k++) {
- res = max(res, rec(i, k) + rec(k + 1, j));
- }
- return dp[i][j] = res;
- }
- int main() {
- ios_base::sync_with_stdio(false);
- int n;
- cin >> n;
- cin >> s;
- compatible[make_pair('A', 'U')] = true;
- compatible[make_pair('U', 'A')] = true;
- compatible[make_pair('C', 'G')] = true;
- compatible[make_pair('G', 'C')] = true;
- compatible[make_pair('G', 'U')] = true;
- compatible[make_pair('U', 'G')] = true;
- memset(dp, -1, sizeof dp);
- cout << rec(0, n - 1) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement