Codeforces 6D Lizards and Basements 2 dfs+暴力

來源:互聯網
上載者:User

標籤:blog   http   get   2014   os   表   

題目連結:點擊開啟連結

#include<stdio.h>#include<iostream>#include<string.h>#include<set>#include<vector>#include<map>#include<math.h>#include<queue>#include<string>#include<stdlib.h>#include<algorithm>using namespace std;#define N 110#define ll intll n, a, b;ll h[N];vector<int>G,ans;void dfs(int u, bool hehe){//hehe=true表示u-1沒死if(u==n && hehe==false){if(G.size()<ans.size())ans = G;return ;}int siz = 0;if(hehe) {while(h[u-1]>0)siz++,h[u-1]-=b, h[u]-=a, h[u+1]-=b, G.push_back(u);}if(h[u]>0) {while(h[u]>0) {dfs(u+1,true);h[u-1]-=b;h[u]-=a;h[u+1]-=b;siz++;G.push_back(u);}}dfs(u+1,false);h[u]+=a*siz;h[u+1]+=b*siz;h[u-1]+=b*siz;while(siz--)G.erase(G.end()-1);}int main(){ll i, j;while(~scanf("%d %d %d",&n,&a,&b)){G.clear(); ans.clear();for(i=1;i<=n;i++)scanf("%d",&h[i]), h[i]++;while(h[1]>0){h[2] -= a;h[1] -= b;h[3] -= b;ans.push_back(2);}while(h[n]>0){h[n-2] -= b;h[n-1] -= a;h[n] -= b;ans.push_back(n-1);}G = ans;for(i=1;i<=100;i++)ans.push_back(i);dfs(2,false);printf("%d\n",ans.size());for(i = 0; i < ans.size(); i++)printf("%d%c",ans[i],i==ans.size()-1?'\n':' ');}return 0;}/**/


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.