Advertisement
Josif_tepe

Untitled

Apr 11th, 2023
559
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cstring>
  4. #include <map>
  5. using namespace std;
  6. const int maxn = 205;
  7. map<pair<char, char>, bool> compatible;
  8. int dp[maxn][maxn];
  9. string s;
  10. int rec(int i, int j) {
  11.     if(j - i <= 1) {
  12.         return 0;
  13.     }
  14.     if(dp[i][j] != -1) {
  15.         return dp[i][j];
  16.     }
  17.     int res = 0;
  18.     if(compatible[make_pair(s[i], s[j])]) {
  19.         res = max(res, rec(i + 1, j - 1) + 1);
  20.     }
  21.     for(int k = i; k < j; k++) {
  22.         res = max(res, rec(i, k) + rec(k + 1, j));
  23.     }
  24.     return dp[i][j] = res;
  25. }
  26. int main() {
  27.     ios_base::sync_with_stdio(false);
  28.     int n;
  29.     cin >> n;
  30.     cin >> s;
  31.    
  32.     compatible[make_pair('A', 'U')] = true;
  33.     compatible[make_pair('U', 'A')] = true;
  34.     compatible[make_pair('C', 'G')] = true;
  35.     compatible[make_pair('G', 'C')] = true;
  36.     compatible[make_pair('G', 'U')] = true;
  37.     compatible[make_pair('U', 'G')] = true;
  38.     memset(dp, -1, sizeof dp);
  39.    
  40.     cout << rec(0, n - 1) << endl;
  41.     return 0;
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement