Advertisement
Josif_tepe

Untitled

Feb 10th, 2022
788
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  1. #include <iostream>
  2. #include <queue>
  3. #include <vector>
  4. #include <cstring>
  5. using namespace std;
  6. int n;
  7. string a;
  8. int memo[50000][4][4][4][4];
  9. int f(int at, int l1,int l2,int r1,int r2){
  10.     if(at>=n){
  11.         return 0;
  12.     }
  13.     if(memo[at][l1][l2][r1][r2] != -1 ){
  14.         return memo[at][l1][l2][r1][r2];
  15.     }
  16.     int res= -1;
  17.     int levo = 0, desno = 0;
  18.     vector<bool> visited(4, false);
  19.     visited[l1] = true;
  20.     visited[l2] = true;
  21.     int colour;
  22.     if(a[at] == 'R'){
  23.         colour = 1;
  24.     }
  25.     if(a[at] == 'Y'){
  26.         colour = 2 ;
  27.     }
  28.     if(a[at] =='G'){
  29.         colour = 3;
  30.     }
  31.     visited[colour] = true;
  32.     levo = f(at+1,colour,l1,r1,r2)+visited[1]+visited[2]+visited[3];
  33.     visited[1]  = false;
  34.     visited[2]  = false;
  35.     visited[3]  = false;
  36.  
  37.     visited[r1] = true;
  38.     visited[r2]= true;
  39.     visited[colour] = true;
  40.     desno  = f(at+1,l1,l2,colour,r1)+visited[1]+visited[2]+visited[3];
  41.     res = max(levo,desno);
  42.     return memo[at][l1][l2][r1][r2] =res;
  43.  
  44. }
  45. int main() {
  46.     cin >> n;
  47.     cin >> a;
  48.     memset(memo,-1,sizeof(memo));
  49.     cout << f(0,0,0,0,0);
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement