当前位置:网站首页>Boss Rush (two-point answer + DP)
Boss Rush (two-point answer + DP)
2022-07-30 04:34:00 【Small dimples.】
Boss Rush
题意
给定 n 个技能,每个技能只能用一次.
Each skill has a cooldown t i t_i ti,If a skill is in time x 释放,那么直到 x + t i − 1 x+t_i-1 x+ti−1 No other skills can be released during this time.
Each skill has a damage duration l e n i len_i leni,If the skill is in time x 释放,Then it will be in th x + j ( 0 ≤ j < l e n i ) x+j\ (0\leq j < len_i) x+j (0≤j<leni) 时刻产生 d i , j d_{i,j} di,j 伤害.
问,Set the life value to H 的 boss How long does it take to beat the minimum?
1 ≤ n ≤ 18 , 1 ≤ H ≤ 1 0 18 , 1 \leq n \leq 18, 1\leq H\leq 10^{18}, 1≤n≤18,1≤H≤1018,
1 ≤ t i , l e n i ≤ 100 000 , 1 ≤ d i , j ≤ 1 0 9 1 \leq t_i,len_i\leq 100\,000,\ 1\leq d_{i,j}\leq 10^9 1≤ti,leni≤100000, 1≤di,j≤109
思路
n 很小,考虑状压DP,Find the maximum damage dealt.
But the time is not fixed,There is no way to minimize the time spent,So consider the dichotomous answer to fix the time,Then in this time frame the pressureDP,See if the maximum damage dealt is greater than that H.
时间复杂度: O ( n ∗ 2 n ∗ l o g a n s ) O(n*2^n*log\ ans) O(n∗2n∗log ans)
Enumerates all collections from small to large,对于当前集合,Iterate over all events that are not in this collection,Use the state of the collection 更新 Plus the state of the collection after the event:
To maximize damage,Each skill is released at the minimum release time.
The minimum time for the current skill to release is ,The sum of the cooldowns of all skills in the set.Damage starts at the time of release,to release time + len[i] - 1 结束,The end time should be equal to the time of two minutes T 取 min.f[i | 1 << j] = max(f[i | 1<<j], f[i] + dmg[j][min(end-sum, len[j]-1)]);
The last time was very tight,to prune.
1.When enumerating all collections,If the current collection has not been updated,Then there is no need to update other collections,直接跳过.So initialization initializes all states to -1,0状态初始为0.If the collection state is -1 就跳过.Because the collection it is about to update has already been deleted 0 Status updated.
2.Exit immediately after the current damage is satisfied,There is no need to update all collections.
3.It is also possible to preprocess the sum of the cooling times for each set,This way you don't have to do it every time.
Code
#include<bits/stdc++.h>
using namespace std;
#define Ios ios::sync_with_stdio(false),cin.tie(0)
#define int long long
const int N = 200010, mod = 1e9+7;
int T, n, m;
int a[N];
int t[20], len[20];
int dmg[20][N];
int f[1<<18];
bool check(int mid)
{
int end = mid;
mem(f, -1);
f[0] = 0;
for(int i=0;i<1<<n;i++)
{
if(f[i] == -1) continue;
int sum = 0;
for(int j=0;j<n;j++) if(i >> j & 1) sum += t[j]; //This block can be preprocessed
if(sum > end) continue;
for(int j=0;j<n;j++)
{
if(i >> j & 1) continue;
f[i | 1 << j] = max(f[i | 1<<j], f[i] + dmg[j][min(end-sum, len[j]-1)]);
if(f[i | 1<<j] >= m) return 1;
}
}
return 0;
}
signed main(){
Ios;
cin >> T;
while(T--)
{
cin >> n >> m;
int l = 0, r = 0;
for(int i=0;i<n;i++) //When using the shape pressure, the array position should be as small as possible0开始
{
cin >> t[i] >> len[i];
for(int j=0;j<len[i];j++)
{
cin >> dmg[i][j];
if(j) dmg[i][j] += dmg[i][j-1];
}
r += t[i] + len[i] - 1; //最大时间
}
while(l < r)
{
int mid = l + r >> 1;
if(check(mid)) r = mid;
else l = mid + 1;
}
if(check(l)) cout << l << endl;
else cout << -1 << endl;
}
return 0;
}
A good combination question!
边栏推荐
猜你喜欢
The leap second that may cause the next "Millennium Bug" is boycotted by tech giants
VUX Datetime 组件compute-days-function动态设置日期列表
Introduction to database - MySQL simple introduction
05全局配置文件application.properties详解
swagger usage tutorial - quick use of swagger
MySQL 字符串拼接 - 多种字符串拼接实战案例
复现XXL-JOB 任务调度中心后台任意命令执行漏洞
cnpm安装步骤
Go 学习笔记(84)— Go 项目目录结构
解决报错SyntaxError: (unicode error) ‘utf-8‘ codec can‘t decode byte 0xb7 in position 0: invalid start b
随机推荐
恐造成下一个“千年虫”的闰秒,遭科技巨头们联合抵制
KubeMeet Registration | The complete agenda of the "Edge Native" Online Technology Salon has been announced!
JQ源码分析(环境处理)
共建共享数字世界的根:阿里云打造全面的云原生开源生态
Unity3D Application模拟进入前后台及暂停
QT(39)-vs开发qt程序提示无法打开源文件
商品管理系统数据库设计--SQL Server
【C语言】程序环境和预处理
(Problem practice) Conditional probability + weight line segment tree + FWT + suffix array
【线性表】- LeetCode力扣三道练习题详解
Database Design of Commodity Management System--SQL Server
Unity beginner 5 cameras follow, border control and simple particle control (2 d)
[C language] Program environment and preprocessing
Machine Learning: Knowing the Dimensionality Reduction Process Through Low Variance Filtering
error: The following untracked working tree files would be overwritten by
Shanxi group (enterprises) in the second network security skills competition part problem WP (8)
数据库概论 - MySQL的简单介绍
文件系统二
Go书籍大全-从初级到高级以及Web开发
获取本机IP和Request的IP