Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <map>
- #include <cstring>
- using namespace std;
- string s;
- int n;
- map<pair<char, char>, bool> mapping;
- int dp[222][222];
- int rec(int i, int j) {
- if(j - i <= 1) {
- return 0;
- }
- if(dp[i][j] != -1) {
- return dp[i][j];
- }
- int result = 0;
- if(mapping[make_pair(s[i], s[j])]) {
- result = max(result, rec(i + 1, j - 1) + 1);
- }
- for(int k = i; k < j; k++) {
- result = max(result, rec(i, k) + rec(k + 1, j));
- }
- return dp[i][j] = result;
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin >> n >> s;
- mapping[make_pair('A', 'U')] = true;
- mapping[make_pair('U', 'A')] = true;
- mapping[make_pair('C', 'G')] = true;
- mapping[make_pair('G', 'C')] = true;
- mapping[make_pair('G', 'U')] = true;
- mapping[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