当前位置:网站首页>2022杭电多校 第三场 B题 Boss Rush
2022杭电多校 第三场 B题 Boss Rush
2022-08-05 00:18:00 【Rain Sure】
题目链接
题目大意
给了我们一个Boss的血量,然后给了我们 n n n个技能,每个技能有施法时间和一个施法过程时间,会造成一个持续性伤害,题目问我们最快什么时候能干掉Boss?
题解
考虑二分答案,然后我们需要进行判定在 m i d mid mid时间时,所能造成的最大伤害是多少,如果大于等于Boss的血量,那么返回true,否则返回false。我们计算最大伤害时,可以考虑使用状压DP, f [ i ] f[i] f[i]中的 i i i表示一个状态——哪一位为1就代表使用过哪些技能。具体状态转移可以看代码
代码
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);cout.tie(0);
#define x first
#define y second
#define int long long
#define endl '\n'
const int inf = 1e9 + 10;
const int maxn = 100010, M = 2000010;
const int mod = 1e9 + 7;
typedef pair<int,int> PII;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
int n, H;
int d[20][maxn], s[20][maxn];
int t[20], len[20];
int f[maxn * 3];
bool check(int mid)
{
memset(f, -1, sizeof f);
f[0] = 0;
for(int i = 0; i < 1 << n; i ++){
int time = 0;
for(int j = 0; j < n; j ++){
if(i >> j & 1) time += t[j];
}
if(time > mid) continue;
for(int j = 0; j < n; j ++){
if(i >> j & 1) continue;
f[i | 1 << j] = max(f[i | 1 << j], f[i] + s[j][min(len[j], mid - time)]);
if(f[i | 1 << j] >= H) return true;
}
}
return false;
}
signed main()
{
IOS;
int T; cin >> T;
while(T --)
{
cin >> n >> H;
int l = 0, r = 0;
for(int i = 0; i < n; i ++){
cin >> t[i] >> len[i];
r += max(t[i], len[i]);
for(int j = 1; j <= len[i]; j ++) cin >> d[i][j];
for(int j = 1; j <= len[i]; j ++) s[i][j] = s[i][j - 1] + d[i][j];
}
while(l < r){
int mid = l + r >> 1;
if(check(mid)) r = mid;
else l = mid + 1;
}
if(!check(l)) cout << -1 << endl;
else cout << l - 1 << endl;
}
return 0;
}
边栏推荐
猜你喜欢

在线中文姓名生成工具推荐

Mathematical Principles of Matrix

3. Actual combat---crawl the result page corresponding to Baidu's specified entry (a simple page collector)

Statistical words (DAY 101) Huazhong University of Science and Technology postgraduate examination questions

oracle创建用户以后的权限问题

KT148A voice chip ic working principle and internal architecture description of the chip

Metasploit-域名上线隐藏IP

oracle创建用户

SQL关联表更新

golang 协程的实现原理
随机推荐
Flask框架 根据源码分析可扩展点
Implementation principle of golang coroutine
Couple Holding Hands [Greedy & Abstract]
KT148A语音芯片ic工作原理以及芯片的内部架构描述
克服项目管理中恐惧心理
Huggingface入门篇 II (QA)
电赛必备技能___定时ADC+DMA+串口通信
Some thoughts on writing
子连接中的参数传递
英特尔WiFi 7产品将于2024年亮相 最高速度可达5.8Gbps
redis可视化管理软件Redis Desktop Manager2022
E - Many Operations (按位考虑 + dp思想记录操作后的结果
2022 Niu Ke Summer Multi-School Training Camp 5 (BCDFGHK)
看图识字,DELL SC4020 / SCv2000 控制器更换过程
How to automatically push my new articles to my fans (very simple, can't learn to hit me)
2022牛客暑期多校训练营5(BCDFGHK)
Will domestic websites use Hong Kong servers be blocked?
RK3399平台开发系列讲解(内核调试篇)2.50、嵌入式产品启动速度优化
机器学习(公式推导与代码实现)--sklearn机器学习库
Modelers experience sharing: model study method