Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- string n;
- int true1;
- int dp[50000][4][4][4][4];
- int rec(int at, int l1, int l2, int r1, int r2){
- if(at==n.size()){
- return 0;
- }
- if(dp[at][l1][l2][r1][r2] != -1) {
- return dp[at][l1][l2][r1][r2];
- }
- int niza[4];
- int lzbir;
- int rzbir;
- int result=0;
- int color=0;
- if(n[at]=='R'){
- color=1;
- }
- if(n[at]=='Y'){
- color=2;
- }
- if(n[at]=='G'){
- color=3;
- }
- for(int i=0; i<4; i++){
- niza[i]=0;
- }
- niza[color]=1;
- niza[l1]=1;
- niza[l2]=1;
- lzbir=niza[1]+niza[2]+niza[3];
- for(int i=0; i<4; i++){
- niza[i]=0;
- }
- niza[color]=1;
- niza[r1]=1;
- niza[r2]=1;
- rzbir=niza[1]+niza[2]+niza[3];
- result=max(result, rec(at+1, color, l1, r1, r2)+lzbir);
- result=max(result, rec(at+1, l1, l2, color, r1)+rzbir);
- dp[at][l1][l2][r1][r2]=result;
- return result;
- }
- int main()
- {
- int golemina;
- cin>>golemina;
- cin>>n;
- for(int i=0; i<50000; i++){
- for(int j=0; j<4; j++){
- for(int k=0; k<4; k++){
- for(int l=0; l<4; l++){
- for(int m=0; m<4; m++){
- dp[i][j][k][l][m]=-1;
- }
- }
- }
- }
- }
- cout<<rec(0, 0, 0, 0, 0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement