NewTrain1 T5: Boss single challenge

Topic analysis

(See this Daguai title, is generally not greedy DP ...)

We found that for this question, so that the state can not be too greedy, so we had to DP.

Because normal attack and magic attack and attack effects are relatively independent, so it can be considered separately.

So fm [i], fs [i] were to use only magic attack and only attack to the i-th round (ending) with normal attacks and special effects that can cause maximum injury (first whether I live or die).

Then make gm [i] [j], gs [i] [j] respectively to the i-th round (ending), magic amount / value of the remaining anger j points that can cause the greatest harm (first whether I live or die).

Then for each fm [i] and fs [i] sweep again updated the answer.

Consider how to maintain gm [i] [j], gs [i] [j].

There are two modes of operation:

     1. To restore mana / rage value.

     2. Use the skills.

They were transferred to.

 

Consider how to arrive at a final answer, we first find the first case of dead or alive, at least a few rounds can kill the Boss.

Make dp [i] [j] to represent the i-th round (ending), blood is j, the maximum use of the skills of the total number of + Pu Gong.

Also has two modes of operation:

     1. To restore the value of life

     2. Use a skill / Pugong

They were transferred to.

If a dp [i] [j] reached the above mentioned minimum number of rounds, then the optimal strategy description at this time to take the words could have been killed Boss, you can output the answer directly.

 

So how to judge it a draw?

If the first data wheel i + 1, it shows to i + 1 can live round outputs Tie.

Conversely certainly lost.

 1 #include<bits/stdc++.h>
 2 #define INTMAX 2147483647LL
 3 #define PII pair<int,int>
 4 #define MK make_pair
 5 #define re register
 6 #define clr(x) memset(x,0,sizeof(x))
 7 using namespace std;
 8 typedef long long ll;
 9 const double Pi=acos(-1.0);
10 const int Inf=0x3f3f3f3f;
11 const int MAXN=1e3+10;
12 inline int read(){
13     re int x=0,f=1,ch=getchar();
14     while(!isdigit(ch))f=ch=='-'?-1:1,ch=getchar();
15     while(isdigit(ch))x=x*10+ch-48,ch=getchar();
16     return x*f;
17 }
18 inline ll readll(){
19     re ll x=0,f=1,ch=getchar();
20     while(!isdigit(ch))f=ch=='-'?-1:1,ch=getchar();
21     while(isdigit(ch))x=x*10+ch-48,ch=getchar();
22     return x*f;
23 }
24 
25 int T,n,m,hp,mp,sp,dhp,dmp,dsp,mp_cnt,sp_cnt,x;
26 int a[MAXN],ump[MAXN],vmp[MAXN],usp[MAXN],vsp[MAXN];
27 int fm[MAXN],gm[MAXN][MAXN],fs[MAXN],gs[MAXN][MAXN],dp[MAXN][MAXN];
28 inline void Up(int &x,int y){if(x<y) x=y;}
29 inline void Solve(){
30     clr(fm);clr(gm);clr(fs);clr(gs);
31     n=read();m=read();hp=read();mp=read();sp=read();dhp=read();dmp=read();dsp=read();x=read();
32     for(int i=1;i<=n;++i) a[i]=read();
33     mp_cnt=read();for(int i=1;i<=mp_cnt;++i) ump[i]=read(),vmp[i]=read();
34     sp_cnt=read();for(int i=1;i<=sp_cnt;++i) usp[i]=read(),vsp[i]=read();
35     for (int i=0;i<=n;++i){
36         for(int j=0;j<=mp;++j) Up(fm[i],gm[i][j]);
37         if(i<n)
38             for(int j=0;j<=mp;++j){
39                 Up(gm[i+1][min(mp,j+dmp)],gm[i][j]);
40                 for(int k=1;k<=mp_cnt;++k)
41                     if(j>=ump[k])
42                         Up(gm[i+1][j-ump[k]],gm[i][j]+vmp[k]);
43             }
44     }
45     for(int i=0;i<=n;++i){
46         for(int j=0;j<=sp;++j) Up(fs[i],gs[i][j]);
47         if(i<n)
48             for(int j=0;j<=sp;++j){
49                 Up(gs[i+1][min(sp,j+dsp)],gs[i][j]+x);
50                 for(int k=1;k<=sp_cnt;++k)
51                     if(j>=usp[k])
52                         Up(gs[i+1][j-usp[k]],gs[i][j]+vsp[k]);
53             }
54     }
55     int mn=Inf;
56     for(int i=0;i<=n;++i)
57         for(int j=0;j<=n;++j)
58             if(fm[i]+fs[j]>=m)
59                 mn=min(mn,i+j);
60     memset(dp,192,sizeof(dp));
61     dp[1][hp]=1;
62     for(int i=1;i<=n;++i){
63         for(int j=1;j<=hp;++j){
64             if(dp[i][j]>=mn){
65                 printf("Yes %d\n",i);
66                 return;
67             }
68         }
69         for(int j=1;j<=hp;++j){
70             if(min(hp,j+dhp)>a[i]) Up(dp[i+1][min(hp,j+dhp)-a[i]],dp[i][j]);
71             if(j>a[i]) Up(dp[i+1][j-a[i]],dp[i][j]+1); 
72         }
73     }
74     for(int i=1;i<=hp;++i)
75         if(dp[n+1][i]>=0){
76             puts("Tie");return;
77         }
78     puts("No");
79 }
80 int main(){
81     T=read();
82     while(T--) Solve();
83     return 0;
84 }

 

Guess you like

Origin www.cnblogs.com/LI-dox/p/11261527.html