当前位置:网站首页>CF6D Lizards and Basements 2题解
CF6D Lizards and Basements 2题解
2022-04-21 06:19:00 【cornivores】
CF6D Lizards and Basements 2
题意:有n个人,编号1到n,每个人有血量 h i h_i hi对某个人攻击会产生a点伤害,会波及到相邻的人,对相邻的人产生b点伤害(1和n号人不能攻击),问最少要攻击多少次才能让所有人的h小于0,分别攻击了谁。
解法:dfs搜索,先处理出每个人最多攻击多少次,对攻击次数枚举,每次保证当前点前所有人h值已经小于0。
代码:
#include<bits/stdc++.h>
using namespace std;
const int N = 20;
int n, a, b, h[N], ci[N], tmp[N];
int res = 1e9, r[N];
void dfs(int step, int ans) {
if(ans >= res) return ;
// cout << step << endl;
if(step == n) {
// cout << ans << " " << res << " " << h[n] << endl;
if(h[n] < 0) {
if(ans < res) {
for(int i = 2; i <= step; ++i) r[i] = tmp[i];
res = ans;
}
}
return;
}
for(int i = 0; i <= ci[step]; ++i) {
if(i*b <= h[step-1]) continue;
tmp[step] = i;
h[step+1] -= i*b;
h[step] -= i*a;
dfs(step+1, ans+i);
h[step+1] += i*b;
h[step] += i*a;
tmp[step] = 0;
}
}
int main() {
scanf("%d%d%d", &n, &a, &b);
for(int i = 1; i <= n; ++i) scanf("%d", &h[i]);
for(int i = 2; i < n; ++i) {
ci[i] = max(h[i]/a, max(h[i-1]/b, h[i+1]/b)) + 1;
}
dfs(2, 0);
printf("%d\n", res);
for(int i = 2; i < n; ++i)
for(int j = 0; j < r[i]; ++j) printf("%d ", i);
puts("");
return 0;
}
版权声明
本文为[cornivores]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_43408978/article/details/109125795
边栏推荐
猜你喜欢
随机推荐
【Labview】记录下做Labview项目的一些坑点
异步RPC的三种方式:异步调用,异步监听,callback调用
[LabVIEW] record some pits in LabVIEW project
Modify the launcher3 icon and add a mask or shadow icon to the icon
2、 3 [FPGA] how to light the LED
2. mysql基本查询
多文件上传(表单提交)
语义的特征提取及简单词频展示(WordCloud)
Pm2 部署 Nuxt 项目
3-1. Pod controller
STM32 H743 ECC内存相关使用说明笔记
win10的jupyter notebook使用pyspark2.3.2解决的报错问题
Swagger2生成Api文档
[AD] modular schematic drawing pit point record
反射执行FlinkSql代码时找不到UDF的class报ClassNotFound
VMware Workstation server service failed to start
电脑内网外网同时访问-解决办法
【ThreadX】H743+ThreadX+FileX移植记录
学习瑞芯微RK3399pro记录(10)
php初级程序员,接单,挣外快的指导方法


![2、 3 [FPGA] how to light the LED](/img/3c/011e9314d99bb58f4234b831df544e.png)





