bzoj 1806

IOI的。。。暴力的动规。。。以后记得不要把DP想得太复杂。。。

 1 #include<bits/stdc++.h>
 2 #define inc(i,l,r) for(i=l;i<=r;i++)
 3 #define dec(i,l,r) for(i=l;i>=r;i--)
 4 #define inf 1e9
 5 #define mem(a) memset(a,0,sizeof(a))
 6 #define ll long long
 7 #define succ(x) (1<<x)
 8 #define NM 100000+5
 9 using namespace std;
10 int read(){
11     int x=0,f=1;char ch=getchar();
12     while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
13     while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
14     return x*f;
15 }
16 char s[NM];
17 int f[4][4][4][4],g[4][4][4][4],i,x1,x2,v,n,y2,t,ans;
18 int add(int v,int x,int y){
19     if(x==0)x=v;
20     if(y==0)y=v;
21     if(x==y&&x==v)return 1;
22     if(x==y||x==v||y==v)return 2;
23     return 3;
24 }
25 int r(char x){
26     if(x=='M')return 1;
27     if(x=='B')return 2;
28     return 3;
29 }
30 int main(){
31     int y1;
32     n=read();
33     scanf("%s",s);
34     g[r(s[0])][0][0][0]=g[0][0][r(s[0])][0]=1;
35     inc(i,1,n-1){
36     v=r(s[i]);mem(f);
37     inc(x1,0,3)
38     inc(x2,0,3)
39     inc(y1,0,3)
40     inc(y2,0,3)
41     if(t=g[x1][x2][y1][y2]){
42 //        printf("%d:%d %d %d %d %d\n",i,x1,x2,y1,y2,t);
43         f[v][x1][y1][y2]=max(f[v][x1][y1][y2],t+add(v,x1,x2));
44         f[x1][x2][v][y1]=max(f[x1][x2][v][y1],t+add(v,y1,y2));
45     }
46     inc(x1,0,3)
47     inc(x2,0,3)
48     inc(y1,0,3)
49     inc(y2,0,3)
50     g[x1][x2][y1][y2]=f[x1][x2][y1][y2];
51     }
52     inc(x1,0,3)
53     inc(x2,0,3)
54     inc(y1,0,3)
55     inc(y2,0,3)
56     ans=max(ans,f[x1][x2][y1][y2]);
57     printf("%d\n",ans);
58     return 0;
59 }
View Code

 

转载于:https://www.cnblogs.com/onlyRP/p/4852228.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值