Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <queue>
- #include <vector>
- #include <cstring>
- using namespace std;
- int n;
- string a;
- int memo[50000][4][4][4][4];
- int f(int at, int l1,int l2,int r1,int r2){
- if(at>=n){
- return 0;
- }
- if(memo[at][l1][l2][r1][r2] != -1 ){
- return memo[at][l1][l2][r1][r2];
- }
- int res= -1;
- int levo = 0, desno = 0;
- vector<bool> visited(4, false);
- visited[l1] = true;
- visited[l2] = true;
- int colour;
- if(a[at] == 'R'){
- colour = 1;
- }
- if(a[at] == 'Y'){
- colour = 2 ;
- }
- if(a[at] =='G'){
- colour = 3;
- }
- visited[colour] = true;
- levo = f(at+1,colour,l1,r1,r2)+visited[1]+visited[2]+visited[3];
- visited[1] = false;
- visited[2] = false;
- visited[3] = false;
- visited[r1] = true;
- visited[r2]= true;
- visited[colour] = true;
- desno = f(at+1,l1,l2,colour,r1)+visited[1]+visited[2]+visited[3];
- res = max(levo,desno);
- return memo[at][l1][l2][r1][r2] =res;
- }
- int main() {
- cin >> n;
- cin >> a;
- memset(memo,-1,sizeof(memo));
- cout << f(0,0,0,0,0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement