当前位置:网站首页>(2022 Hangdian multi school III) 1002 boss rush (pressure dp+ dichotomy)
(2022 Hangdian multi school III) 1002 boss rush (pressure dp+ dichotomy)
2022-07-29 03:32:00 【AC__ dream】
Topic link :ssss - Virtual Judge

The sample input :
3
1 100
5 3
50 60 70
2 100
2 3
40 40 100
100 2
20 5
1 1000
1 1
999Sample output :
1
2
-1The question : Multiple sets of samples , Each group of samples is given one n and H, Represent the number of skills and boss Blood volume , Next, there are two lines of input for each skill , The first line gives two numbers, representing the skill use time t[i] And skill duration len[i], The next line shows len[i] Number , Each second can be represented by Boss Damage done , After we use a skill , During the use of this skill, you will Boss Cause harm , But you can't use other skills , Ask us to kill Boss Minimum time required , If you can't kill Boss Output directly -1.
analysis : Take a look at the data range , At most, there are only 18 individual , Then I thought of using shape pressing , We can have two minutes , Set the bisection boundaries as 0,1e18, Then the binary complexity is log(1e18),f[st] Indicates that the skill use status is st The maximum damage caused in a certain period of time under the condition of ( A certain period of time is a binary ), The update process is n*2^n, So the overall complexity is O(log(1e18)*n*2^n).
Let's take a look at how to perform dynamic transfer .
We have to decide whether we can T Defeat in time Boss, So our f[st] It means that the skill use status is st Under the condition of time T Internal pair Boss The maximum damage caused , We need to go from 1~(1<<n) Enumerate skill usage status st, We need to preprocess the time required to reach any state , If the current state is st, If the damage value of the current state is greater than Boss Blood volume H, Then we'll go straight back true, If the current state takes longer than T, Then we don't need to continue to update the next state of the current state , Because using the current state to update the next state will use more skills , It will take more time , It makes no sense . We update the status to enumerate the skills that have not been used in the current status , For example, skills i, If section i The total time still hasn't arrived after skills T, Then we will take all the damage value of the current skill into account f[st|(1<<i)], If you use the i The total time after skills exceeds T, Since our skill damage has been calculated since the beginning of use , So we just need to calculate in T The damage caused by this period of time before time can be . Note that we use skills to achieve st The time required , That is to say, the sum of skill release time is not the sum of skill duration , We must make clear the relationship between the two , Follow this update process to update the answer , If it is updated to the end, there is no status st bring f[st]>=H, So return false.
Here is the code :
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
#include<vector>
#include<cmath>
using namespace std;
const int N=1e5+10;
typedef long long ll;
ll sum[20][N];//sum[i][j] It means the first one i Before skills j The damage that seconds can cause
ll H,n,t[20],len[20];
ll f[1<<20];//f[st] According to state st The most damage caused in a certain period of time ( A certain period of time is a binary )
ll sumt[1<<20];//sumt[st] Indicates that the trigger skill is in the state st The minimum trigger time required
bool check(ll T)
{
ll ans=0;
for(int i=1;i<1<<n;i++) f[i]=-1;
f[0]=0;
for(int st=0;st<1<<n;st++)
{
ll w=f[st];
if(w==-1) continue;// State the current state st stay t It cannot be triggered completely in time
if(w>=H) return true;// Description status st Next in t The damage caused in time can already kill the monster
if(sumt[st]>T) continue;
for(int i=0;i<n;i++)// Enumerate skills that have not been triggered
{
if(st>>i&1) continue;// This skill has been triggered
if(sumt[st]+len[i]-1<=T)
f[st|(1<<i)]=max(f[st|(1<<i)],f[st]+sum[i][len[i]]);
else
f[st|(1<<i)]=max(f[st|(1<<i)],f[st]+sum[i][T-sumt[st]+1]);
}
}
return false;
}
int main()
{
int T;
cin>>T;
while(T--)
{
scanf("%lld%lld",&n,&H);
for(int i=0;i<n;i++)
{
scanf("%lld%lld",&t[i],&len[i]);
for(int j=1;j<=len[i];j++)
{
scanf("%lld",&sum[i][j]);
sum[i][j]+=sum[i][j-1];
}
}
for(int st=1;st<1<<n;st++)// Preprocessing trigger skill in status st The minimum trigger time required
{
sumt[st]=0;// Don't forget to initialize
for(int i=0;i<n;i++)
if(st>>i&1) sumt[st]+=t[i];
}
ll l=0,r=1e18;
while(l<r)
{
ll mid=l+r>>1;
if(check(mid)) r=mid;
else l=mid+1;
}
if(check(l)) printf("%lld\n",l);
else puts("-1");
}
return 0;
}边栏推荐
- Numpy acceleration -- > cupy installation
- 1.5 nn. Module neural network (III)
- Sanzi chess (player + computer)
- Does domestic ERP have a chance to beat sap?
- makefile详解
- 军品技术文件划分及说明
- Mathematical modeling -- analytic hierarchy process model
- A case of gradually analyzing the splitting of classes -- colorful ball collisions
- xxxxx
- 04 | background login: login method based on account and password (Part 1)
猜你喜欢

Rdkit II: use rdkit screening to screen 2D pharmacophores of chemical small molecules

for_each用法示例

CUDA GDB prompt: /tmp/tmpxft**** cudafe1.stub. c: No such file or directory.

Excel拼接数据库语句

Design of smoke temperature, humidity and formaldehyde monitoring based on single chip microcomputer

Asynchronous callback future mode of concurrent mode

Violence recursion to dynamic programming 01 (robot movement)

Exness: dove resolution helped gold rebound, and the focus turned to U.S. GDP

3D advanced renderer: artlandis studio 2021.2 Chinese version

July 28, 2022 Gu Yujia's study notes
随机推荐
NXP i.mx8mp-deepviewrt
Learn exkmp again (exkmp template)
xxxxx
安装抓包证书
for_ Example of each usage
Example analysis of while, repeat and loop loops in MySQL process control
STC MCU drive 1.8 'TFT SPI screen demonstration example (including data package)
军品研制过程-转阶段
Summary of basic knowledge points of C language
通过递归实现多级联动
Swing V2: towards a larger model with larger capacity and higher resolution
Suffix automata (SAM) board from Jly
Configure vscade to realize ROS writing
Mathematical modeling -- analytic hierarchy process model
Matlab learning - accumulation of small knowledge points
Tonight at 7:30 | is the AI world in the eyes of Lianjie, Jiangmen, Baidu and country garden venture capital continue to be advanced or return to the essence of business
i. MX 8m plus integrated dedicated neural processing engine (NPU)
Three military product baselines (functional baseline, distribution baseline, product baseline) and the documents contained in the baseline
How dare you write a resume that is proficient in concurrent programming? Why do you use a two-way linked list in AQS?
C language programming | exchange binary odd and even bits (macro Implementation)