101 to 010 Atcoder CODE FESTIVAL 2017 qual B D

Posted hehe54321

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了101 to 010 Atcoder CODE FESTIVAL 2017 qual B D相关的知识,希望对你有一定的参考价值。

https://www.luogu.org/problemnew/show/AT3575

题解

根本不会。。

错误记录:缺少32行的转移。显然这个转移是必要的

技术分享图片
 1 #include<cstdio>
 2 #include<algorithm>
 3 #include<cstring>
 4 #include<vector>
 5 using namespace std;
 6 #define fi first
 7 #define se second
 8 #define mp make_pair
 9 #define pb push_back
10 typedef long long ll;
11 typedef unsigned long long ull;
12 typedef pair<int,int> pii;
13 
14 int a[500010],ans[500010],pre[500010];
15 int n;
16 int main()
17 {
18     int i;
19     scanf("%d",&n);
20     for(i=1;i<=n;++i)
21         scanf("%1d",&a[i]);
22     for(i=1;i<=n;++i)
23         pre[i]=a[i]==0?i:pre[i-1];
24     int pre2=0;
25     for(i=1;i<=n;++i)
26     {
27         if(i>=3&&a[i]==1&&a[i-1]==0&&a[i-2]==1)    pre2=i;
28         ans[i]=ans[i-1];
29         if(i>=3&&a[i-2]==1&&a[i-1]==0&&a[i]==1)
30         {
31             ans[i]=max(ans[i],ans[pre[i-2]]+(i-2-pre[i-2]));
32             ans[i]=max(ans[i],ans[pre[i-2]+1]+(i-2-(pre[i-2]+1)));
33         }
34         if(pre2>pre[i])
35         {
36             ans[i]=max(ans[i],ans[pre2-3]+(i-pre2+1));
37         }
38         //printf("1t%d %d
",i,ans[i]);
39     }
40     printf("%d",ans[n]);
41     return 0;
42 }
View Code

 

以上是关于101 to 010 Atcoder CODE FESTIVAL 2017 qual B D的主要内容,如果未能解决你的问题,请参考以下文章

AT3575 101 to 010(DP)

AtCoder Regular Contest 101

AtCoder Regular Contest 101

[Atcoder Code Festival 2017 Qual B Problem F]Largest Smallest Cyclic Shift

AtCoder Contest 167 A - F 解题报告

AtCoder Contest 167 A - F 解题报告