题意:n个人站成一行,现在要杀死这n个人,每次可以选择攻击一个人当攻击此人时可以减掉他a的血量,同时在他旁边的两个人也将会减少b的血量,求最少需要多少次能杀死所有的人,只能攻击低2到第n-1号人
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<list>
#include<queue>
#include<vector>
using namespace std;
vector<int>temp,ans;
int num[15],n,a,b;
void dfs(int arc,bool die){
if(arc==n&&die){
if(temp.size()<ans.size()){
ans=temp;
}
return ;
}
int cnt=0;
while(num[arc-1]>=0){
num[arc-1]-=b;num[arc]-=a;num[arc+1]-=b;
temp.push_back(arc);cnt++;
}
while(num[arc]>=0){
dfs(arc+1,false);
num[arc-1]-=b;num[arc]-=a;num[arc+1]-=b;
temp.push_back(arc);cnt++;
}
dfs(arc+1,true);
num[arc]+=a*cnt;
num[arc+1]+=b*cnt;
num[arc-1]+=b*cnt;
while(cnt--)temp.erase(temp.end()-1);
}
int main()
{
int i,j,k;
scanf("%d%d%d",&n,&a,&b);
//memset(num,-1,sizeof(num));
for(i=1;i<=n;++i){
scanf("%d",&num[i]);
}
while(num[1]>=0){
num[1]-=b;num[2]-=a;num[3]-=b;
ans.push_back(2);
}
while(num[n]>=0){
num[n]-=b;num[n-1]-=a;num[n-2]-=b;
ans.push_back(n-1);
}temp=ans;
for(i=1;i<=100;++i){
ans.push_back(i);
}
dfs(2,true);
printf("%d\n",ans.size());
for(i=0;i<ans.size()-1;++i){
printf("%d ",ans[i]);
}
printf("%d\n",ans[ans.size()-1]);
return 0;
}