题意

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[( << )], *p1 = buf, *p2 = buf;
#define LL long long
using namespace std;
const int MAXN = * 1e6 + ;
inline int read() {
char c = getchar(); int x = , f = ;
while(c < '' || c > '') {if(c == '-') f = -; c = getchar();}
while(c >= '' && c <= '') x = x * + c - '', 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[];
struct Enemy {
int H, A, D, S, ap, dp, mp, hp;
}a[];
vector<int> v[];
void init() {
memset(f, , sizeof(f));
Hp = read(); A = read(); F = read(); M = read();
N = read();
lim = Po[N];
for(int i = ; 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 = ; i <= N; i++) v[i].clear();
for(int i = ; 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 & ) aa = A, d = D; // 模仿
if (s & ) D = ; // 无视防御
LL AA = max(0ll, A - d); // 勇士造成伤害
aa = max(0ll, aa - D) * (((s >> ) & ) + ); // 怪物造成的攻击力,是否连击
if (AA == ) return ;
LL t1 = (h - ) / AA + ; // 需要打怪几次
LL t2 = (s & ) ? (t1 * aa) : ((t1 - ) * aa); // 怪造成的攻击力,是否有先攻
LL t3 = max(0ll, t2 - M); // 减去魔防
return max(0ll, Now - t3);
}
void solve() {
f[] = Hp;
for(int sta = ; sta < lim; sta++) {
IA[sta] = A; IF[sta] = F; IM[sta] = M;
for(int i = ; i <= N; i++)
if(sta / Po[i - ] % == )
IA[sta] += a[i].ap, IF[sta] += a[i].dp, IM[sta] += a[i].mp;
}
for(int sta = ; sta < lim; sta++) {
if(f[sta] == ) continue;
for(int i = ; i <= N; i++) {
if(sta / Po[i - ] % == ) {// not kill
bool flag = ;
for(int j = ; j < v[i].size(); j++)
if(sta / Po[v[i][j] - ] % == ) // not kiil
{flag = ; break;}
if(flag == ) continue;
LL nhp = Attack(sta, i);
if(nhp > )
f[sta + Po[i - ]] = max(f[sta + Po[i - ]], nhp);
} else if(sta / Po[i - ] % == ) {
f[sta + Po[i - ]] = max(f[sta + Po[i - ]], f[sta] + a[i].hp);
}
}
}
printf("%lld\n", f[lim - ] == ? - : f[lim - ]);
}
main() {
Po[] = ;
for(int i = ; i <= ; i++) Po[i] = * Po[i - ];
T = read();
while(T--) {
init();
solve();
}
return ;
}
/*
2 2 1
1 1
2 1 1
*/

ZRDay6A. 萌新拆塔(三进制状压dp)的更多相关文章

  1. HDU 3001 三进制状压DP

    N个城市,M条道路,每条道路有其经过的代价,每一个城市最多能够到达两次,求走全然部城市最小代价,起点随意. 三进制状压.存储每一个状态下每一个城市经过的次数. 转移方程: dp[i+b[k]][k]= ...

  2. hdu 3001 Travelling 经过所有点(最多两次)的最短路径 三进制状压dp

    题目链接 题意 给定一个\(N\)个点的无向图,求从任意一个点出发,经过所有点的最短路径长度(每个点至多可以经过两次). 思路 状态表示.转移及大体思路 与 poj 3311 Hie with the ...

  3. Travelling (三进制+状压dp)

    题目链接 #include <bits/stdc++.h> using namespace std; typedef long long ll; inline ll read(){ ,f= ...

  4. HDU - 3001 Travelling(三进制状压dp)

    Travelling After coding so many days,Mr Acmer wants to have a good rest.So travelling is the best ch ...

  5. UVA 10817 - Headmaster's Headache(三进制状压dp)

    题目:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=20&pag ...

  6. HDU 3001 三进制 状压dp

    Travelling Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  7. 三进制状压 HDOJ 3001 Travelling

    题目传送门 题意:从某个点出发,所有点都走过且最多走两次,问最小花费 分析:数据量这么小应该是状压题,旅行商TSP的变形.dp[st][i]表示状态st,在i点时的最小花费,用三进制状压.以后任意进制 ...

  8. Codeforces Round #297 (Div. 2) [ 折半 + 三进制状压 + map ]

    传送门 E. Anya and Cubes time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  9. hdu3001(三进制状压)

    题目大意: 现在给你一个有n个点和m条边的图,每一条边都有一个费用,每个点不能经过超过两次,求所有点至少遍历一次的最小费用 其中n<=10 m没有明确限制(肯定不会超过1e5) 一看到这个数据范 ...

随机推荐

  1. day02笔记

    1.linux环境配置阿里云yum源 linux软件包管理之 yum工具(如同pip3工具) pip3是管理python模块的工具,自动解决模块依赖,降低开发人员心智负担 pip3 install f ...

  2. RabbitMQ权限

    RabbitMQ 引言 RabbitMQ是一个在AMQP基础上完整的,可复用的企业消息系统.他遵循Mozilla Public License开源协议. MQ全称为Message Queue, 消息队 ...

  3. 1095 Cars on Campus(30 分

    Zhejiang University has 8 campuses and a lot of gates. From each gate we can collect the in/out time ...

  4. maven插件: shade, assembly

    shade插件的作用: 通过版本的exclution无法解决jar冲突的问题, 解决方案是把依赖的包打到本model的jar中,打包的时候由mvn plugin自动修改代码中的依赖jar包名 relo ...

  5. 练习六:斐波那契数列(fibonacci)

    题目:斐波那契数列. 程序分析:斐波那契数列(Fibonacci sequence),又称黄金分割数列,指的是这样一个数列:0.1.1.2.3.5.8.13.21.34.……. 在数学上,斐波那契数列 ...

  6. Silverlight 登陆界面

    美术水平有限,不喜勿喷. 界面代码,效果如下图 <UserControl x:Class="ElecDemoTelerikSL.Login" xmlns="http ...

  7. Eclipse与异常处理

    快捷键:Ctrl+d删除光标所在的这一行 Alt+/ 智能提示 异常处理 异常是阻止当前方法或作用域继续执行的问题,在程序中导致程序中断运行的一些指令. try与catch关键字 try{ //有可能 ...

  8. 【Linux】Linux常用命令大全

    系统信息 arch 显示机器的处理器架构(1) uname -m 显示机器的处理器架构(2) uname -r 显示正在使用的内核版本 dmidecode -q 显示硬件系统部件 - (SMBIOS ...

  9. VS2017无法进入断点调试且移动到breakpoint上的时候报错“breakpoint will not currently be hit. the source code is different from original version. ”

    我尝试了网上的很多其他办法也翻阅了很多外网资源,这些方法并不能解决我的问题 当然我非常震惊正当我尝试着在stack overflow上发表评论交流一下究竟如何解决的时候,却发现有方法灵验了 ,但是每个 ...

  10. 给类型为text的input设置value值却无法修改

    给类型为text的input设置value值后就无法修改了 我的页面显示为如下但是退格却无法改变他的值 原来是缺少onChange事件,没法监听value的改变 所以需要添加 onChange={th ...