Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- int max(int a,int b){
- return (a > b ? a : b);
- }
- int idx(char c){
- if(c == 'M'){
- return 1;
- }
- else if(c == 'B'){
- return 2;
- }
- else if(c == 'F'){
- return 3;
- }
- return -1;
- }
- int point(int N,int L,int O){
- bool check[4];for(int i=0;i<4;i++)check[i] = false;
- int sum = 0;
- if(!check[N]){
- sum++;
- check[N] = true;
- }
- if(!check[L] && L != 0){
- sum++;
- check[L] = true;
- }
- if(!check[O] && O != 0){
- sum++;
- check[O] = true;
- }
- return sum;
- }
- int dp[2][4][4][4][4];
- int main()
- {
- int n;
- scanf("%d",&n);
- char str[100010];
- scanf("%s",str);
- for(int i = n - 1 ; i >= 0 ; i--){
- for(int La = 0 ; La < 4 ; La ++){
- for(int Oa = 0 ; Oa < 4 ; Oa ++){
- for(int Lb = 0 ; Lb < 4 ; Lb ++){
- for(int Ob = 0 ; Ob < 4 ; Ob ++){
- int Nx = idx(str[i]);
- dp[i%2][La][Oa][Lb][Ob] = max(point(Nx,La,Oa) + dp[(i+1)%2][Nx][La][Lb][Ob] , point(Nx,Lb,Ob) + dp[(i+1)%2][La][Oa][Nx][Lb]);
- }
- }
- }
- }
- }
- printf("%d",dp[0][0][0][0][0]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment