1. 程式人生 > >101 to 010 Atcoder CODE FESTIVAL 2017 qual B D

101 to 010 Atcoder CODE FESTIVAL 2017 qual B D

hide clas bsp img 技術 return org include blog

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\n",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