题意
Sol
这好像是我第一次接触三进制状压
首先,每次打完怪之后吃宝石不一定是最优的,因为有模仿怪的存在,可能你吃完宝石和他打就GG了。。
因此我们需要维护的状态有三个
0:没打
1:打了怪物 没吃宝石
2:打了怪物 吃了宝石
如果我们能知道打了那些怪,吃了那些宝石,那么此时的状态时确定的,预处理出来
然后DP就行了
mdzz这题卡常数
/* 首先打完怪之后吃宝石不一定是最优的 因此我们需要枚举出每个怪物的状态 0:没打 1:打了怪物 没吃宝石 2:打了怪物 吃了宝石 如果我们能知道打了那些怪,吃了那些宝石,那么此时的状态时确定的 */ #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<map> #include<vector> #include<set> #include<queue> #include<cmath> //#define int long long #define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1<<22, stdin), p1 == p2) ? EOF : *p1++) char buf[(1 << 22)], *p1 = buf, *p2 = buf; #define LL long long using namespace std; const int MAXN = 2 * 1e6 + 10; inline int read() { char c = getchar(); int x = 0, f = 1; while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();} while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return x * f; } int T, N; int lim, Hp, A, F, M, Mp[MAXN], IA[MAXN], IF[MAXN], IM[MAXN];//攻击 血量 防御 魔防 LL f[MAXN], Po[16]; struct Enemy { int H, A, D, S, ap, dp, mp, hp; }a[15]; vector<int> v[16]; void init() { memset(f, 0, sizeof(f)); Hp = read(); A = read(); F = read(); M = read(); N = read(); lim = Po[N]; for(int i = 1; i <= N; i++) { a[i].H = read(); a[i].A = read(); a[i].D = read(); a[i].S = read(); a[i].ap = read(); a[i].dp = read(); a[i].mp = read(); a[i].hp = read(); } int K = read(); for(int i = 1; i <= N; i++) v[i].clear(); for(int i = 1; i <= K; i++) { int u = read(), vv = read(); v[vv].push_back(u); } } LL Attack(int sta, int id) { LL Now = f[sta], A = IA[sta], D = IF[sta], M = IM[sta]; LL s = a[id].S, h = a[id].H, aa = a[id].A, d = a[id].D; if (s & 8) aa = A, d = D; // 模仿 if (s & 2) D = 0; // 无视防御 LL AA = max(0ll, A - d); // 勇士造成伤害 aa = max(0ll, aa - D) * (((s >> 2) & 1) + 1); // 怪物造成的攻击力,是否连击 if (AA == 0) return 0; LL t1 = (h - 1) / AA + 1; // 需要打怪几次 LL t2 = (s & 1) ? (t1 * aa) : ((t1 - 1) * aa); // 怪造成的攻击力,是否有先攻 LL t3 = max(0ll, t2 - M); // 减去魔防 return max(0ll, Now - t3); } void solve() { f[0] = Hp; for(int sta = 0; sta < lim; sta++) { IA[sta] = A; IF[sta] = F; IM[sta] = M; for(int i = 1; i <= N; i++) if(sta / Po[i - 1] % 3 == 2) IA[sta] += a[i].ap, IF[sta] += a[i].dp, IM[sta] += a[i].mp; } for(int sta = 0; sta < lim; sta++) { if(f[sta] == 0) continue; for(int i = 1; i <= N; i++) { if(sta / Po[i - 1] % 3 == 0) {// not kill bool flag = 0; for(int j = 0; j < v[i].size(); j++) if(sta / Po[v[i][j] - 1] % 3 == 0) // not kiil {flag = 1; break;} if(flag == 1) continue; LL nhp = Attack(sta, i); if(nhp > 0) f[sta + Po[i - 1]] = max(f[sta + Po[i - 1]], nhp); } else if(sta / Po[i - 1] % 3 == 1) { f[sta + Po[i - 1]] = max(f[sta + Po[i - 1]], f[sta] + a[i].hp); } } } printf("%lld ", f[lim - 1] == 0 ? -1 : f[lim - 1]); } main() { Po[0] = 1; for(int i = 1; i <= 15; i++) Po[i] = 3 * Po[i - 1]; T = read(); while(T--) { init(); solve(); } return 0; } /* 2 2 1 1 1 2 1 1 */