当前位置:网站首页>Cf6d lizards and fundamentals 2 problem solving
Cf6d lizards and fundamentals 2 problem solving
2022-04-23 06:29:00 【cornivores】
CF6D Lizards and Basements 2
The question : Yes n personal , Number 1 To n, Everyone has blood h i h_i hi An attack on someone can have a Point injury , It will affect the neighboring people , Have an impact on the neighbors b Point injury (1 and n No one can attack ), Ask how many times you must attack at least to make everyone h Less than 0, Who were attacked .
solution :dfs Search for , First deal with the maximum number of attacks each person can make , Enumerate the number of attacks , Ensure that everyone before the current point every time h The value is already less than 0.
Code :
#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://yzsam.com/2022/04/202204210615591742.html
边栏推荐
- [leetcode 202] happy number
- 检测技术与原理
- [leetcode 19] delete the penultimate node of the linked list
- Addition, deletion, modification and query of MySQL table
- Algèbre linéaire chapitre 2 - matrice et son fonctionnement
- Collections multiple parameter sorting
- Reading of denoising papers - [cvpr2022] blind2blind: self supervised image denoising with visible blind spots
- The problem that the page will refresh automatically after clicking the submit button on the form is solved
- Optional best practices
- Doomsday (simple computational geometry)
猜你喜欢
Kalman filter and inertial integrated navigation
Advanced operation of idea debug
电机与拖动(戚金清版)学习整理
C language file operation
MySQL advanced query
[leetcode 202] happy number
Generate excel template (drop-down selection, multi-level linkage)
List segmentation best practices
Substring Inversion (Easy Version)
Comparative study paper - [Moco, cvpr2020] momentum contract for unsupervised visual representation learning
随机推荐
Database - sorting data
Kalman filter and inertial integrated navigation
Viewer: introduce MySQL date function
[leetcode 459] duplicate substring
Preparedstatement prevents SQL injection
[untitled] database - limit the number of returned rows
JDBC tool class encapsulation
PHP processing JSON_ Decode() parses JSON stringify
Motor and drive (Qi Jinqing Edition)
2. Average length of words
Practical operation - Nacos installation and configuration
How does MySQL convert stored seconds into dates
[leetcode 6] zigzag transformation
MySQL basic madness theory
Formation à la programmation
Export of data
Kibana search syntax
[leetcode 228] summary interval
卡尔曼滤波与惯性组合导航
C3p0 database connection pool usage