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 secondsmemory limit per test64 megabytes
#### 问题描述
> 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
> 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.
输入
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.
输出
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.
样例输入
3 2 1
2 2 2
样例输出
3
2 2 2
题意
现在有n个弓箭手从1到n排成一排,每个人有hi的血量,你只能用火球术去杀死他们,如果你对第i个人使用火球术,将对他造成a点伤害,并且对i-1,i+1造成b点的火焰伤害,你不能直接打第1个和第n个人,问至少需要使用多少次火球术能杀死所有的弓箭手。
题解
首先想到把每人的血量作为状态,这样状态是15^10,QAQ。
正解:dp[i][j][k][l]代表,你现在打算打第i个人,且第i-1个人的血量为j,第i个人的血量为k,第i+1个人的血量为l。
dp[1][h[0]][h[1]][h[2]]=0.
代码
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<ctime>
#include<vector>
#include<cstdio>
#include<string>
#include<bitset>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
#define X first
#define Y second
#define mkp make_pair
#define lson (o<<1)
#define rson ((o<<1)|1)
#define mid (l+(r-l)/2)
#define sz() size()
#define pb(v) push_back(v)
#define all(o) (o).begin(),(o).end()
#define clr(a,v) memset(a,v,sizeof(a))
#define bug(a) cout<<#a<<" = "<<a<<endl
#define rep(i,a,b) for(int i=a;i<(b);i++)
#define scf scanf
#define prf printf
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef vector<pair<int,int> > VPII;
const int INF=0x3f3f3f3f;
const LL INFL=10000000000000000LL;
const double eps=1e-9;
const double PI = acos(-1.0);
//start----------------------------------------------------------------------
int dp[15][20][20][20];
int v[15];
int n,a,b;
struct Node{
int i,j,k,l;
bool operator == (const Node& tmp){
return i==tmp.i&&j==tmp.j&&k==tmp.k&&l==tmp.l;
}
Node(int i,int j,int k,int l):i(i),j(j),k(k),l(l){}
Node(){}
}pre[15][20][20][20];
int main() {
scf("%d%d%d",&n,&a,&b);
for(int i=0;i<n;i++){
scf("%d",&v[i]);
v[i]++;
}
clr(dp,0x3f);
int INF=dp[0][0][0][0];
dp[1][v[0]][v[1]][v[2]]=0;
for(int i=1;i<n-1;i++){
for(int j=v[i-1];j>=0;j--){
for(int k=v[i];k>=0;k--){
for(int l=v[i+1];l>=0;l--){
if(dp[i][j][k][l]>=INF) continue;
if(j==0&&dp[i+1][k][l][v[i+2]]>dp[i][j][k][l]){
dp[i+1][k][l][v[i+2]]=dp[i][j][k][l];
pre[i+1][k][l][v[i+2]]=pre[i][j][k][l];
}
int nj=max(0,j-b);
int nk=max(0,k-a);
int nl=max(0,l-b);
if(dp[i][nj][nk][nl]>dp[i][j][k][l]+1){
dp[i][nj][nk][nl]=dp[i][j][k][l]+1;
pre[i][nj][nk][nl]=Node(i,j,k,l);
}
if(nj==0&&dp[i+1][nk][nl][v[i+2]]>dp[i][j][k][l]+1){
dp[i+1][nk][nl][v[i+2]]=dp[i][j][k][l]+1;
pre[i+1][nk][nl][v[i+2]]=Node(i,j,k,l);
}
}
}
}
}
prf("%d\n",dp[n-2][0][0][0]);
Node tmp=pre[n-2][0][0][0];
while(1){
prf("%d ",tmp.i+1);
if(tmp==Node(1,v[0],v[1],v[2])) break;
tmp=pre[tmp.i][tmp.j][tmp.k][tmp.l];
}
return 0;
}
//end-----------------------------------------------------------------------
Codeforces Beta Round #6 (Div. 2 Only) D. Lizards and Basements 2 dp的更多相关文章
- 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 simpl ...
- 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+ ...
随机推荐
- 关于 SSIS 并行foreach loop的一个设计思路
SSIS 包在控制流方面的性能优化,主要是提高并行度. 可以设置并发线程数MaxConcurrentExecuteables. SSIS中的foreach loop container 不是并行执行任 ...
- Ngrok远程桌面及ssh配置
上一篇Ngrok 内网穿透利器 使用教程我们讲到Ngrok的基本使用教程,这篇描述一下Ngrok的远程桌面及ssh配置 Step 1 修改配置文件ngrok.cfg server_addr: &quo ...
- 第23章 SEH结构化异常处理(1)_系统SEH机制
23.1 基础知识 23.1.1 Windows下的软件异常 (1)中断和异常 ①中断是由外部硬件设备或异步事件产生的 ②异常是由内部事件产生的,可分为故障.陷阱和终止三类. (2)两种异常处理机制: ...
- 第17章 内存映射文件(3)_稀疏文件(Sparse File)
17.8 稀疏调拨的内存映射文件 17.8.1 稀疏文件简介 (1)稀疏文件(Sparse File):指的是文件中出现大量的0数据,这些数据对我们用处不大,但是却一样的占用空间.NTFS文件系统对此 ...
- C/C++ 常用工具集
1. c++filt //注意:就是这个名字 "c++file". 能把c++的函数签名转换成代码形参格式: 如:# c++filt _ZNSt4priv17_Rb_tree_i ...
- Gradle的HelloWorld
Gradle的脚本名为 build.gradle task hello{ doLast{ println("Hello World") } } 运行:gradle -q hell ...
- 微软职位内部推荐-Software Development Engineer 2
微软近期Open的职位: SDE II Organization Summary: Engineering, Customer interactions & Online (ECO) is l ...
- WP老杨解迷:评论数和下载量、榜单的关系
书接上回,继续研讨评论系统的深层经验,这次从另外一个角度看清榜单关系,提升装逼水准2个加号,如果你能看懂本文,并活学活用,足可在Win10之前醉卧隆中,通晓Windows Phone市场风云变幻,哪些 ...
- 分享JS代码(转)
var imgUrl = 'http://xxx/share_ico.png'; // 分享后展示的一张图片 var lineLink = 'http://xxx'; // 点击分享后跳转的页面地址 ...
- 基于React Native的Material Design风格的组件库 MRN
基于React Native的Material Design风格的组件库.(为了平台统一体验,目前只打算支持安卓) 官方网站 http://mrn.js.org/ Github https://git ...