Advertisement
Josif_tepe

Untitled

Feb 9th, 2022
734
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.49 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4. int dp[2][4][4][4][4];
  5.  
  6. int main()
  7. {
  8.     int n;
  9.     cin >> n;
  10.     string s;
  11.     cin >> s;
  12.     for(int i = 0; i < 2; i++) {
  13.         for(int j = 0; j < 4; j++) {
  14.             for(int k = 0; k < 4; k++) {
  15.                 for(int x = 0; x < 4; x++) {
  16.                     for(int y = 0; y < 4; y++) {
  17.                         dp[i][j][k][x][y] = -2e9;
  18.                     }
  19.                 }
  20.             }
  21.         }
  22.     }
  23.     dp[0][0][0][0][0] = 0;
  24.     int color = 0;
  25.     int cost, next, now;
  26.     for(int i = 0; i < n; i++) {
  27.         for(int l1 = 0; l1 < 4; l1++) {
  28.             for(int l2 = 0; l2 < 4; l2++) {
  29.                 for(int r1 = 0; r1 < 4; r1++) {
  30.                     for(int r2 = 0; r2 < 4; r2++) {
  31.                         now = i % 2;
  32.                         next = 1 - now;
  33.                         vector<bool> visited(4, false);
  34.                         if(s[i] == 'R') color = 1;
  35.                         if(s[i] == 'Y') color = 2;
  36.                         if(s[i] == 'G') color = 3;
  37.                         visited[color] = true;
  38.                         visited[l1] = true;
  39.                         visited[l2] = true;
  40.                         cost = visited[1] + visited[2] + visited[3];
  41.                         dp[next][color][l1][r1][r2] = max(dp[next][color][l1][r1][r2],
  42.                                                            dp[now][l1][l2][r1][r2] + cost);
  43.                         visited[1] = false;
  44.                         visited[2] = false;
  45.                         visited[3] = false;
  46.                         visited[color] = true;
  47.                         visited[r1] = true;
  48.                         visited[r2] = true;
  49.                         cost = visited[1] + visited[2] + visited[3];
  50.                         dp[next][l1][l2][color][r1] = max(dp[next][l1][l2][color][r1],
  51.                                                            dp[now][l1][l2][r1][r2] + cost);
  52.                        
  53.                        
  54.                     }
  55.                 }
  56.             }
  57.         }
  58.     }
  59.     int result = 0;
  60.    
  61.     for(int i = 0; i < 2; i++) {
  62.         for(int j = 0; j < 4; j++) {
  63.             for(int k = 0; k < 4; k++) {
  64.                 for(int x = 0; x < 4; x++) {
  65.                     for(int y = 0; y < 4; y++) {
  66.                         result = max(result, dp[i][j][k][x][y]);
  67.                     }
  68.                 }
  69.             }
  70.         }
  71.     }
  72.     cout << result << endl;
  73.     return 0;
  74. }
  75.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement