题意:有一串数字,每一次你可以使一个数字减少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;
}

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 nintegers — 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

Input
3 2 1
2 2 2

Output
3
2 2 2 

Input
4 3 1
1 4 1 1

Output
4
2 2 3 3 

CodeForces 6D Lizards and Basements 2(DFS)相关推荐

  1. CodeForces 6D Lizards and Basements 2 (dfs)

    题意:给出一串n个元素序列.a和b,只能选择编号2 ~ n-1的s数字减a,并将相邻两数字减b,要使得所有元素为负,问至少需要多少次选择,选择是怎样的. 题解:dfs 我们可以发现只有2 ~ n-1编 ...

  2. Codeforces 897C Nephren gives a riddle(DFS)

    Codeforces:Nephren gives a riddle time limit per test: 2 seconds memory limit per test: 256 megabyte ...

  3. 【Codeforces 723D】Lakes in Berland (dfs)

    海洋包围的小岛,岛内的有湖,'.'代表水,'*'代表陆地,给出的n*m的地图里至少有k个湖,求填掉面积尽量少的水,使得湖的数量正好为k. dfs找出所有水联通块,判断一下是否是湖(海水区非湖).将湖按 ...

  4. Codeforces 982 C. Cut 'em all!(dfs)

    解题思路: 代码中有详细注解,以任意一点为根,dfs遍历这棵树. 每一个节点可能有好几个子树,计算每棵子树含有的节点数,再+1即为这整棵树的节点. 判断子树是否能切断与根之间的联系,如果子树含有偶数个 ...

  5. 大盘点|6D姿态估计算法汇总(下)

    作者:Tom Hardy Date: 2019-12-28 来源:大盘点|6D姿态估计算法汇总(下)

  6. 三十二、图的创建深度优先遍历(DFS)广度优先遍历(BFS)

    一.图的基本介绍 为什么要有图 前面我们学了线性表和树 线性表局限于一个直接前驱和一个直接后继的关系 树也只能有一个直接前驱也就是父节点 当我们需要表示多对多的关系时, 这里我们就用到了图. 图的举例 ...

  7. 【 MATLAB 】离散傅里叶级数(DFS)及 IDFS 的 MATLAB 实现

    有关离散傅里叶级数(DFS)我之前也写过一些博文,例如:离散周期信号的傅里叶级数(DFS) 这里我再次给出标准公式. 分析式: 其中: 综合式: 这里我必须先声明,关于分析式和综合式前面那个系数1/N ...

  8. 部署分布式文件系统(DFS)

    部署分布式文件系统(DFS) 使用 DFS 命名空间,可以将位于不同服务器上的共享文件夹组合到一个或多个逻辑结构的命名空间.每个命名空间作为具有一系列子文件夹的单个共享文件夹显示给用户.但是,命名空间 ...

  9. Java实现算法导论中图的广度优先搜索(BFS)和深度优先搜索(DFS)

    对算法导论中图的广度优先搜索(BFS)和深度优先搜索(DFS)用Java实现其中的伪代码算法,案例也采用算法导论中的图. import java.util.ArrayList; import java ...

最新文章

  1. idea运行两个tomcat_IDE里的Tomcat是如何工作的
  2. AutoML综述更新 【AutoML:Survey of the State-of-the-Art】
  3. Unity中对象池的使用
  4. IP协议包中的TTL(Time-To-Live)
  5. 【例1】 给定n(n>=1),用递归的方法计算1+2+3+4+...+(n-1)+n。
  6. 【Django】基于Django架构网站代码的目录结构
  7. Docker 1.0对OpenStack意味着什么
  8. 渲染已保存的几何图形
  9. 走进C++程序世界-----函数相关(全局变量)
  10. 孙鑫VC学习笔记:第三讲 MFC应用程序框架
  11. 504.七进制数(力扣leetcode) 博主可答疑该问题
  12. VS2008简体中文版下载及安装破解
  13. 高速钢(HSS)金属切削刀具的全球与中国市场2022-2028年:技术、参与者、趋势、市场规模及占有率研究报告
  14. yigo基础学习笔记4_业务流程
  15. 华北赛区承办学校:太原工业学院
  16. 处理深度学习中数据集不平衡问题方法汇总
  17. Unity碰撞检测机制的原理(更新中...)
  18. three.js加载obj模型和材质
  19. 电商产品设计:促销活动设计解析
  20. 在C4D和Keyshot中保存产品模型到预设库多次重复使用

热门文章

  1. appium使用sendkeys输入银行卡卡号(每4个数字自动空一格)总是输入不正确的解决办法
  2. 微信小游戏跳跳快乐方块制作全过程
  3. 站在行业C位,谷医堂打开健康管理服务新思路
  4. 每日一个小技巧:1招教你怎么将照片无损放大
  5. PTA 火星数字(java)
  6. EditText 实时显示输入的字数与最大输入限制长度
  7. ACM练级日志:微软编程之美比赛测试赛-3(高精度相关)
  8. mac 安装oracle
  9. java rtmp服务器_RTMP服务器安装
  10. unity脚本控制逐渐消失_Unity实现物体逐渐消失(逐渐出现)