当前位置:网站首页>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
边栏推荐
- Installation and usage skills of idea
- GNU EFI header file
- Export of data
- SQL -- data definition
- Formation à la programmation
- In depth source code analysis servlet first program
- Implementation of displaying database pictures to browser tables based on thymeleaf
- 4. Print form
- 2. Average length of words
- ValueError: loaded state dict contains a parameter group that doesn‘t match the size of optimizer‘s
猜你喜欢
Generation of verification code
[leetcode 67] sum of two binary numbers
Guaba and Computational Geometry
Addition, deletion, query and modification of data
Installation and usage skills of idea
Kibana search syntax
Class loading and classloader understanding
Algèbre linéaire chapitre 1 - déterminants
MySQL table constraints and table design
Kalman filter and inertial integrated navigation
随机推荐
Example of ticket selling with reentrant lock
[leetcode 54] spiral matrix
Numpy common function table sorting of data processing
Miscellaneous 1
Linear algebra Chapter 2 - matrices and their operations
POI and easyexcel exercises
Implementation of displaying database pictures to browser tables based on thymeleaf
Understanding and use of tp50, tp90 and tp99
JDBC connection database
Animation - Introduction to keyframes
ThreadLocal. Threadlocalmap analysis
Viewer: introduce MySQL date function
Rainbow (DP)
[leetcode 150] evaluation of inverse Polish expression
Busybox initrd and initialization process
Database - sorting data
-- SQL query and return limit rows
Detection technology and principle
St table template
Class loading and classloader understanding