ZRDay6A. 萌新拆塔(三进制状压dp)
题意


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)的更多相关文章
- HDU 3001 三进制状压DP
N个城市,M条道路,每条道路有其经过的代价,每一个城市最多能够到达两次,求走全然部城市最小代价,起点随意. 三进制状压.存储每一个状态下每一个城市经过的次数. 转移方程: dp[i+b[k]][k]= ...
- hdu 3001 Travelling 经过所有点(最多两次)的最短路径 三进制状压dp
题目链接 题意 给定一个\(N\)个点的无向图,求从任意一个点出发,经过所有点的最短路径长度(每个点至多可以经过两次). 思路 状态表示.转移及大体思路 与 poj 3311 Hie with the ...
- Travelling (三进制+状压dp)
题目链接 #include <bits/stdc++.h> using namespace std; typedef long long ll; inline ll read(){ ,f= ...
- HDU - 3001 Travelling(三进制状压dp)
Travelling After coding so many days,Mr Acmer wants to have a good rest.So travelling is the best ch ...
- UVA 10817 - Headmaster's Headache(三进制状压dp)
题目:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=20&pag ...
- HDU 3001 三进制 状压dp
Travelling Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 三进制状压 HDOJ 3001 Travelling
题目传送门 题意:从某个点出发,所有点都走过且最多走两次,问最小花费 分析:数据量这么小应该是状压题,旅行商TSP的变形.dp[st][i]表示状态st,在i点时的最小花费,用三进制状压.以后任意进制 ...
- Codeforces Round #297 (Div. 2) [ 折半 + 三进制状压 + map ]
传送门 E. Anya and Cubes time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- hdu3001(三进制状压)
题目大意: 现在给你一个有n个点和m条边的图,每一条边都有一个费用,每个点不能经过超过两次,求所有点至少遍历一次的最小费用 其中n<=10 m没有明确限制(肯定不会超过1e5) 一看到这个数据范 ...
随机推荐
- 关于webpack的版本导致的postcss-loader的问题
来源自问题 https://segmentfault.com/q/1010000006987956 !!!发现这解决方案还是不能用,估计是webpack又更新了一轮,请看看下下方的答案 某个版本web ...
- LeetCode 024 Swap Nodes in Pairs 交换链表中相邻的两个节点
Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2-> ...
- Unity UGUI按钮添加点击事件
1. 可视化创建及事件绑定 # 1 : 通过 Hierarchy 面板创建 UI > Button. 2 : 创建一个脚本 TestClick.cs, 定义了一个 Click 的 public ...
- MapReduce的输入格式
1. InputFormat接口 InputFormat接口包含了两个抽象方法:getSplits()和creatRecordReader().InputFormat决定了Hadoop如何对文件进行分 ...
- VirtualBox 在Centos 7 中安装增强功能 (共享文件夹)
1.分配光驱 2.安装相关依赖包 yum install -y bzip2 gcc gcc-devel gcc-c++ gcc-c++-devel make kernel-d 3.创建临时文件夹 mk ...
- SQLServer数据库语句大全汇总
目录清单CONTEXT LIST1.数据库DataBase 1.1数据库建立/删除create/drop database 1.2数据库备份与恢复backup/restore database2.数据 ...
- Spring scope 配置
Scope 描述的是 Spring 容器如何新建Bean的实例,Spring的Scope有以下几种,通过@Scope来注解实现: 1. Singleton: 一个Spring容器中只有一个Bean的实 ...
- 一个简单的EventEmitter
用JS写了一个简单的EventEmitter: class EventEmitter { /** * 事件名/回调列表 字典 * @type {Map<string, Array<func ...
- Hibernate笔记7--JPA CRUD
1.环境搭建,注意包结构的问题,src下建立名为META-INF的文件夹,放persistence.xml,位置放错,读不到会报错. <?xml version="1.0" ...
- instanceof 关键字
boolean = Object(类引用名) instanceof Class(类名) 作用:判断符号左边的引用指向的对象是否是右边这个类的对象: