当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
随机推荐
图解 Canvas 入门
英特尔WiFi 7产品将于2024年亮相 最高速度可达5.8Gbps
KT148A语音芯片ic工作原理以及芯片的内部架构描述
Handwritten Distributed Configuration Center (1)
LeetCode Hot 100
could not build server_names_hash, you should increase server_names_hash_bucket_size: 32
软件测试面试题:请你分别画出 OSI 的七层网络结构图和 TCP/IP 的四层结构图?
matlab中rcosdesign函数升余弦滚降成型滤波器
ansible学习笔记分享-含剧本示例
Cloud native - Kubernetes 】 【 scheduling constraints
[LeetCode] Summary of Matrix Simulation Related Topics
【unity编译器扩展之模型动画拷贝】
电赛必备技能___定时ADC+DMA+串口通信
KT6368A Bluetooth certification problem_FCC and BQB_CE_KC certification or other instructions
软件测试面试题:负载测试、容量测试、强度测试的区别?
软件开发工具的技术要素
00、数组及字符串常用的 API(详细剖析)
After another 3 days, I have sorted out 90 NumPy examples, and I can't help but bookmark it!
redis可视化管理软件Redis Desktop Manager2022
倒计时1天!8月2日—4日与你聊聊开源与就业那些事!