题解 CF6D CF6D Lizards and Basements 2

时间:2019-08-31
本文章向大家介绍题解 CF6D CF6D Lizards and Basements 2,主要包括题解 CF6D CF6D Lizards and Basements 2使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

$dfs$ 好啊

题意

有一队人,你可以用火球点某个人,会对当前人造成a点伤害,对旁边的人造成b点伤害。

不能打1号和n号,求最少多少发点死所有人。

Note 

一个人被打死当且仅当它的血量 <0。

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cmath>
 5 #include<cstdlib>
 6 #include<algorithm>
 7 #include<string>
 8 #define ll long long
 9 #define maxn 100005
10 #define inf 2147483647
11 #define mod 10003
12 #define eps 1e-6
13 #define pi acos(-1.0)
14 #define de(x) ((x)*(x))
15 using namespace std; 
16 inline int read(){
17 int x=0,f=1; char ch=getchar();
18 while(!isdigit(ch)) {if(ch=='-')f=-1;ch=getchar();}
19 while(isdigit(ch)) {x=x*10+ch-48;ch=getchar();}
20 return x*f;
21 }
22 int n,a,b,h[15],tot,ans;
23 int p[155],val[155];
24 inline void check(){
25 int yu=max(h[n-1]/a+(h[n-1]>=0),h[n]/b+(h[n]>=0));
26 for(int i=1;i<=yu;i++) p[++tot]=n-1;
27 if(ans>tot){
28 for(int i=1;i<=tot;i++) val[i]=p[i];
29 ans=tot;
30 }
31 tot-=yu;
32 }
33 inline void dfs(int now){//标准的dfs
34 if(now>n-1) {check();return;}
35 if(h[now-1]<0) dfs(now+1);
36 int last=tot,A=h[now-1],B=h[now],C=h[now+1];
37 while(1){
38 h[now]-=a; h[now-1]-=b;
39 h[now+1]-=b; p[++tot]=now;
40 if(h[now-1]<0) dfs(now+1);
41 if((h[now-1]<0&&h[now]<0)||tot>=ans){
42 tot=last;
43 h[now-1]=A; h[now]=B; h[now+1]=C;
44 break;
45 }
46 }
47 }
48 signed main(){
49 n=read(); a=read(); b=read();
50 for(int i=1;i<=n;i++) h[i]=read();
51 ans=inf; tot=0;
52 dfs(2);
53 printf("%d\n",ans);
54 for(int i=1;i<=ans;i++) printf("%d ",val[i]);
55 return 0;
56 }
yyy

原文地址:https://www.cnblogs.com/cbyyc/p/11440424.html