Codeforces Beta Round #6 (Div. 2 Only) D. Lizards and Basements 2 dfs
D. Lizards and Basements 2
题目连接:
http://codeforces.com/contest/6/problem/D
Description
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Sample Input
3 2 1
2 2 2
Sample Output
3
2 2 2
Hint
题意
你是火系法师,你可以扔火球,你每次可以使得砸中的人掉a血,使得相邻的掉b血
然后问你最少多少次,可以砸死所有人
你只能攻击2-n-1,切可以攻击已经死去的人。
题解:
数据范围太小了,自信dfs一波就好了
代码
#include<bits/stdc++.h>
using namespace std;
int ans=1e9,h[15],n,a,b;
vector<int> T,T2;
void dfs(int x,int times)
{
if(times>=ans)return;
if(x==n)
{
if(h[x]<0)
{
T2=T;
ans=times;
}
return;
}
for(int i=0;i<=max(h[x-1]/b+1,max(h[x]/a+1,h[x+1]/b+1));i++)
{
if(h[x-1]<b*i)
{
h[x-1]-=b*i;
h[x]-=a*i;
h[x+1]-=b*i;
for(int j=0;j<i;j++)T.push_back(x);
dfs(x+1,times+i);
for(int j=0;j<i;j++)T.pop_back();
h[x-1]+=b*i;
h[x]+=a*i;
h[x+1]+=b*i;
}
}
}
int main()
{
scanf("%d%d%d",&n,&a,&b);
for(int i=1;i<=n;i++)scanf("%d",&h[i]);
dfs(2,0);
cout<<ans<<endl;
for(int i=0;i<T2.size();i++)
cout<<T2[i]<<" ";
cout<<endl;
}
Codeforces Beta Round #6 (Div. 2 Only) D. Lizards and Basements 2 dfs的更多相关文章
- Codeforces Beta Round #6 (Div. 2 Only) D. Lizards and Basements 2 dp
题目链接: http://codeforces.com/problemset/problem/6/D D. Lizards and Basements 2 time limit per test2 s ...
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
- Codeforces Beta Round #79 (Div. 2 Only)
Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...
- Codeforces Beta Round #77 (Div. 2 Only)
Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...
- Codeforces Beta Round #76 (Div. 2 Only)
Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...
- Codeforces Beta Round #75 (Div. 2 Only)
Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...
- Codeforces Beta Round #74 (Div. 2 Only)
Codeforces Beta Round #74 (Div. 2 Only) http://codeforces.com/contest/90 A #include<iostream> ...
- Codeforces Beta Round #73 (Div. 2 Only)
Codeforces Beta Round #73 (Div. 2 Only) http://codeforces.com/contest/88 A 模拟 #include<bits/stdc+ ...
随机推荐
- discuz各个目录与文件的作用说明
discuz下面有很多文件夹以及文件,你们都知道他们是做什么的么?肯定不知道了吧.但是我们有经常遇到这些文件,譬如在后台文件校验操作都遇到某些文件被修改,这时候也需要知道这些文件是有什么作用的.今天就 ...
- Term Term ssh登陆linux后 显示乱码
setup----terminal----locale----“chinese” OK!!!!!
- 121.Best Time to Buy and Sell Stock---dp
题目链接:https://leetcode.com/problems/best-time-to-buy-and-sell-stock/description/ 题目大意:给出一串数组,找到差值最大的差 ...
- 苹果的浏览器safari无法识别 2016-1-1这样的日期,会返回Invalid Date
1.很多时候我们遇到的日期是2016-1-1这样的,中间是带横线的,但是有时候我们需要转化为标准的时间,即使用new Date(time)这样的方法,这时在safari浏览器里面Invalid Dat ...
- python中__dict__与dir()的区别
在python中__dict__与dir()都可以返回一个对象的属性,区别在于: __dict__是对象的一个属性,而dir()是一个built-in的方法: __dict__返回一个对象的属性名和值 ...
- [笔记]用gdb调试core dump
总是隔一段时间才写一次C++,有些东西老是用完就忘了……记一下如何用gdb来调试core dump免得到时候又忘记. 首先需要设置core file的大小,默认是0所以不设不会生成core file ...
- Download failed : Oracle JDK 7 is NOT installed,解决oracle jdk7的问题
先了解下概念: jdk(java development kit),就是java的开发工具集,顾名思义就是做开发用的,其中包括javac,也就是java compiler等.jre(java runt ...
- awk练习总结
>>> >>>awk是个优秀文本处理工具,可以说是一门程序设计语言.下面是awk内置变量. 一.内置变量表 属性 说明 $0 当前记录(作为单个变量) $1~$n ...
- MQTT协议以及库函数说明
内容简介:之前我们写了一篇ESP8266AT指令的说明文档,在客户端连接上服务器之后,接下来便是网络通信.为此我们又写了这一片MQTT协议的说明文档,更加深层次的讲述了通信的原理.此文档只是我们在调试 ...
- 【WPF】城市级联(XmlDataProvider)
首先在绑定的时候进行转换: public class RegionConverter : IValueConverter { public object Convert(object value, T ...