码迷,mamicode.com
首页 > 其他好文 > 详细

1489 蜥蜴和地下室

时间:2018-11-28 13:17:26      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:res   namespace   include   ==   pre   color   div   space   main   

 1 #include<iostream>
 2 using  namespace  std;
 3 const int INF =10000000;
 4 int n,a,b;
 5 int h[12];
 6 int res;
 7 int res_dp=INF;
 8 void dp(int N,int ans)
 9 {
10     if (N==n-1)
11     {
12         res_dp=res_dp > ans ? ans : res_dp;
13         return ;    
14     }    
15     if (h[N-1]<0)
16     {dp(N+1,ans);}
17     int time=0;
18     if (h[N-1]>=0)
19     {
20         time=h[N-1]/b+1;
21         h[N-1] -=time*b;
22         h[N] -=time*a;
23         h[N+1]  -=time*b;
24         dp(N+1,ans+time);
25         h[N-1]+=time*b;
26         h[N] +=time*a;
27         h[N+1] +=time*b;    
28     }
29     int time_=h[N]/a+1;
30     
31     if (h[N]>=0&&time_>time)
32     {
33         for (int i=time+1;i<=time_;i++)
34         {
35             h[N-1]-=b*i;
36             h[N] -=a*i;
37             h[N+1]-=b*i;
38             dp(N+1,ans+i);
39             h[N-1] +=b*i;
40             h[N] +=a*i;
41             h[N+1] +=b*i;
42         }    
43     }
44     return  ;
45 }
46 int main()
47 {
48     cin>>n>>a>>b;
49     for (int i=0;i<n;i++)
50     {
51         cin>>h[i];
52     }
53     int time1 = h[0]/b+1;
54     h[0]-=b*time1;
55     h[1]-=a*time1;
56     h[2]-=b*time1;
57     res+=time1;
58     if (h[n-1]>=0){
59     int time2 = h[n-1]/b+1;
60     h[n-1]-=b*time2;
61     h[n-2]-=b*time2;
62     h[n-3]-=b*time2;
63     res+=time2 ;
64     }
65     dp(1,0);
66     if (res_dp==INF)res_dp=0;
67     //cout<<res<<endl;
68     cout<<res_dp+res;
69 }

 

1489 蜥蜴和地下室

标签:res   namespace   include   ==   pre   color   div   space   main   

原文地址:https://www.cnblogs.com/biubiuWham/p/10031471.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!