101 to 010 Atcoder CODE FESTIVAL 2017 qual B D

來源:互聯網
上載者:User

標籤:hide   cto   open   make   www.   not   lua   htm   max   

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_back10 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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.