当前位置:网站首页>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;
}
边栏推荐
- 00、数组及字符串常用的 API(详细剖析)
- About I double-checked and reviewed the About staff page, returning an industry question
- 子连接中的参数传递
- Couple Holding Hands [Greedy & Abstract]
- oracle创建用户以后的权限问题
- 怎么将自己新文章自动推送给自己的粉丝(巨简单,学不会来打我)
- KT148A语音芯片ic工作原理以及芯片的内部架构描述
- How to burn the KT148A voice chip into the chip through the serial port and the tools on the computer
- Cython
- MAUI Blazor 权限经验分享 (定位,使用相机)
猜你喜欢

what?测试/开发程序员要被淘汰了?年龄40被砍到了32?一瞬间,有点缓不过神来......

电赛必备技能___定时ADC+DMA+串口通信

英特尔WiFi 7产品将于2024年亮相 最高速度可达5.8Gbps

The master teaches you the 3D real-time character production process, the game modeling process sharing

2022 Niu Ke Summer Multi-School Training Camp 5 (BCDFGHK)

SQL association table update

国内网站用香港服务器会被封吗?

找不到DiscoveryClient类型的Bean

大师教你3D实时角色制作流程,游戏建模流程分享

Mysql_14 存储引擎
随机推荐
【unity编译器扩展之模型动画拷贝】
Three tips for you to successfully get started with 3D modeling
Will domestic websites use Hong Kong servers be blocked?
IDEA file encoding modification
lua 如何 实现一个unity协程的工具
GO中sync包自由控制并发的方法
KT6368A蓝牙的认证问题_FCC和BQB_CE_KC认证或者其它说明
"Relish Podcast" #397 The factory manager is here: How to use technology to empower the law?
Couple Holding Hands [Greedy & Abstract]
could not build server_names_hash, you should increase server_names_hash_bucket_size: 32
DNS常见资源记录类型详解
【LeetCode】图解 904. 水果成篮
电子行业MES管理系统的主要功能与用途
uinty lua 关于异步函数的终极思想
TinyMCE disable escape
《WEB安全渗透测试》(28)Burp Collaborator-dnslog外带技术
jenkins发送邮件系统配置
建模师经验分享:模型学习方法
数据类型及输入输出初探(C语言)
KT148A voice chip ic working principle and internal architecture description of the chip