SuitNdtie

Miner PROG2003

Apr 13th, 2019
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. int max(int a,int b){
  4.     return (a > b ? a : b);
  5. }
  6. int idx(char c){
  7.     if(c == 'M'){
  8.         return 1;
  9.     }
  10.     else if(c == 'B'){
  11.         return 2;
  12.     }
  13.     else if(c == 'F'){
  14.         return 3;
  15.     }
  16.     return -1;
  17. }
  18. int point(int N,int L,int O){
  19.     bool check[4];for(int i=0;i<4;i++)check[i] = false;
  20.     int sum = 0;
  21.     if(!check[N]){
  22.         sum++;
  23.         check[N] = true;
  24.     }
  25.     if(!check[L] && L != 0){
  26.         sum++;
  27.         check[L] = true;
  28.     }
  29.     if(!check[O] && O != 0){
  30.         sum++;
  31.         check[O] = true;
  32.     }
  33.     return sum;
  34. }
  35. int dp[2][4][4][4][4];
  36.  
  37. int main()
  38. {
  39.     int n;
  40.     scanf("%d",&n);
  41.     char str[100010];
  42.     scanf("%s",str);
  43.     for(int i = n - 1 ; i >= 0 ; i--){
  44.         for(int La = 0 ; La < 4 ; La ++){
  45.             for(int Oa = 0 ; Oa < 4 ; Oa ++){
  46.                 for(int Lb = 0 ; Lb < 4 ; Lb ++){
  47.                     for(int Ob = 0 ; Ob < 4 ; Ob ++){
  48.                         int Nx = idx(str[i]);
  49.                         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]);
  50.                     }
  51.                 }
  52.             }
  53.         }
  54.     }
  55.     printf("%d",dp[0][0][0][0][0]);
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment