HDU 2809 God of War (状压DP)
God of War
Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1671 Accepted Submission(s): 647
Problem Description
184~280 A.D ,there were many kingdoms in China. Three strongest among
them are "Wei", "Shu", "Wu". People call this period as "Three
Kingdoms".
HH is a super "Three Kingdoms" fan, because at this period
there were many heroes and exciting stories. Among the heroes HH
worships LvBu most.
LvBu is the God of War and is also intelligent,
but his ambition is too big while enemies are too powerful .Many
monarchs wanted to kill him.
At 198 A.D ,CaoCao fought with LvBu at
Xuzhou.Though Lvbu is the God of War ,CaoCao had so many generals:
Xuchu,DianWei XiahouChun……Facing so many heroes ,could LvBu beat all of
them?

Given
the LvBu's ATI, DEF, HP, and enemies’ ATI, DEF,HP, experience (if LvBu
killed one of his enemies, he can get that experience ,and if his
experience got more than or equal to 100*level,he would level-up and
become stronger) and the In_ATI,In_DEF,In_HP(indicating when LvBu levels
up,his ability will increase this point).
Each turn LvBu will choose an enemy to fight. Please help LvBu find a way to beat all of enemies and survive with the max HP.
Here’s a fight between LvBu and A:
If LvBu attack A, A will lose Max(1,LvBu's ATI- A's DEF) hp;
If A survived, he will give LvBu Max(1,A'ATI- LvBu'DEF) injury.
If LvBu is still alive, repeat it untill someone is dead(hp <= 0).
LvBu's initial level is 1 and experience is 0,and he can level up many times.
Input
For each case , the first line contains six intergers ,indicating LvBu's ATI,DEF,HP and In_ATI,In_DEF,In_HP.
The next line gives an interger N(0<N<=20),indicating the number of the enemies .
Then
N lines followed, every line contains the name(the length of each name
is no more than 20),ATI,DEF,HP, experience(1<experience<=100).
Output
Or output the maximum HP left.
Sample Input
ZhangFei
XuChu GuanYu
Sample Output
Poor LvBu,his period was gone.
题目大意
吕布去打架,有n个对手,告诉你吕布初始攻击力 防御力 生命值 还有每次升级对于三项属性的增加量 以及n个对手的三项属性 和击败他们所能获得的经验值 每次经验值过100就会升级
每次战斗时,都是吕布先出手,双方造成的伤害是攻击力减防御力。
问吕布能否将对手全部击败,如果能就输出最后的最大生命值,否则输出"Poor LvBu,his period was gone."
题目分析
状压DP,用二进制代表当前已经击败的敌人,dp[i]代表达到当前状态所能维持的最大血量,每次看这个敌人有没有攻击,没有攻击就和他打,打完看能不能更新dp数组即可。
#include<bits/stdc++.h> using namespace std; struct
{
int ati;
int def;
int hp;
int exp;
}lvbu[<<],a[]; int inati,indef,inhp,n,i,N,j,nati,ndef,nhp,nexp,att,lose,attime,deftime;
string str; int main()
{
while(scanf("%d%d%d%d%d%d",&lvbu[].ati,&lvbu[].def,&lvbu[].hp,&inati,&indef,&inhp)!=EOF)
{
lvbu[].exp=;
cin>>n;
for(i=;i<n;i++)
{
cin>>str>>a[i].ati>>a[i].def>>a[i].hp>>a[i].exp;
}
N=(<<n)-; //这个地方一定不要写成 1<<n-1 会被解释成 1<<(n-1)的!!!
for(i=;i<=N;i++)
{
lvbu[i].hp=;
}
for(i=;i<=N;i++)
{
for(j=;j<n;j++)
{
if(lvbu[i].hp>&&(!(i&(<<j)))) //当前状态还有血并且没有和第j个敌人交战
{
att=max(,lvbu[i].ati-a[j].def); //吕布一刀砍多少
lose=max(,a[j].ati-lvbu[i].def); //敌人一刀砍多少
attime=(a[j].hp+att-)/att; //打死敌人需要的次数 向上取整
deftime=(lvbu[i].hp+lose-)/lose; //敌人打死吕布需要的次数
if(attime>deftime)
continue;
nhp=lvbu[i].hp-lose*(attime-);
nexp=lvbu[i].exp+a[j].exp;
ndef=lvbu[i].def;
nati=lvbu[i].ati;
if(nexp>=)
{
nhp+=inhp;
ndef+=indef;
nati+=inati;
nexp-=;
}
if(lvbu[i|<<j].hp<=nhp)
{
lvbu[i|<<j].hp=nhp;
lvbu[i|<<j].def=ndef;
lvbu[i|<<j].ati=nati;
lvbu[i|<<j].exp=nexp;
}
}
}
}
if(lvbu[N].hp)
cout<<lvbu[N].hp<<endl;
else
cout<<"Poor LvBu,his period was gone."<<endl;
}
}
HDU 2809 God of War (状压DP)的更多相关文章
- HDU 6149 Valley Numer II 状压DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6149 题意:中文题目 解法:状压DP,dp[i][j]代表前i个低点,当前高点状态为j的方案数,然后枚 ...
- HDU 5434 Peace small elephant 状压dp+矩阵快速幂
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5434 Peace small elephant Accepts: 38 Submissions: ...
- HDU 1074 Doing Homework(状压DP)
第一次写博客ORZ…… http://acm.split.hdu.edu.cn/showproblem.php?pid=1074 http://acm.hdu.edu.cn/showproblem.p ...
- HDU 4906 Our happy ending (状压DP)
HDU 4906 Our happy ending pid=4906" style="">题目链接 题意:给定n个数字,每一个数字能够是0-l,要选当中一些数字.然 ...
- HDU 1074 Doing Homework (状压dp)
题意:给你N(<=15)个作业,每个作业有最晚提交时间与需要做的时间,每次只能做一个作业,每个作业超出最晚提交时间一天扣一分 求出扣的最小分数,并输出做作业的顺序.如果有多个最小分数一样的话,则 ...
- HDU 4568 Hunter 最短路+状压DP
题意:给一个n*m的格子,格子中有一些数,如果是正整数则为到此格子的花费,如果为-1表示此格子不可到,现在给k个宝藏的地点(k<=13),求一个人从边界外一点进入整个棋盘,然后拿走所有能拿走的宝 ...
- HDU 1074 Doing Homework【状压DP】
Doing Homework Problem Description Ignatius has just come back school from the 30th ACM/ICPC. Now he ...
- HDU 4899 Hero meet devil (状压DP, DP预处理)
题意:给你一个基因序列s(只有A,T,C,G四个字符,假设长度为n),问长度为m的基因序列s1中与给定的基因序列LCS是0,1......n的有多少个? 思路:最直接的方法是暴力枚举长度为m的串,然后 ...
- HDU 5657 CA Loves Math 状压DP + 枚举
题意: 给出\(A(2 \leq A \leq 11), n(0 \leq n \leq 10^9), k(1 \leq k \leq 10^9)\). 求区间\([1, A^n]\)中各个数字互不相 ...
- HDU - 4284 Travel(floyd+状压dp)
Travel PP loves travel. Her dream is to travel around country A which consists of N cities and M roa ...
随机推荐
- fiddler-重定向AutoResponder(三)
关于Fiddler的AutoResponder重定向功能,主要是时进行会话的拦截,然后替换原始资源的功能. 它与手动修该reponse是一样的,只是更加方便了,可以创建相应的rules,适合批处理的重 ...
- jprofiler 监听远程java项目
1.下载.安装windows和linux版的jprofile.注意:若监控的是springboot.springcloud项目,切记本地和服务器上的jprofile要版本保持一致,本人亲自踩过坑. 官 ...
- [Jenkins]Job中如何传递自定义变量
场景一: Job构建步骤间的变量传递 Jenkins提供了数十种构建方式,我们以最常用的『Execute shell』为例.有时为了使Job中的复杂的构建流程更加清晰我们配置多个构建步骤像下面这样.图 ...
- 论文阅读:ClickNF: a Modular Stack for Custom Network Functions
摘要: 网络功能虚拟化最近允许用等效的软件实现代替专用设备, Click路由器是朝这个方向迈出的第一步,它定义了用于通用数据包处理的模块化平台. 尽管Click具有重大影响,但它不提供本机L4实现,而 ...
- PyQT5堆叠布局:切换界面(QStackedLayout)
几乎所有的GUI界面都需要用到这个场景:在一个界面里面,点击不同的按钮显示不同的内容 在Qt设计师中没有堆叠布局,需要我们手动添加 在Qt设计师中,设计3个切换的页面,和一个主界面. 注意在主界面是两 ...
- sqli-labs(40)
0X01同样是构造闭合 这里的闭合条件是') 构造语句 ?id=');insert into users values(100,'tx','tx')%23 在客户端mysql里面看看 嘿嘿 成功执行 ...
- Spring boot之JPA/Hibernate/Spring Data
1.什么是JPA? JPA全称Java Persistence API.JPA通过JDK 5.0注解或XML描述对象-关系表的映射关系,并将运行期的实体对象持久化到数据库中. JPA(Java Per ...
- java @Value注解 和 @Data注解
@Value注解 service层代码 @Service public class HelloServiceImpl implements HelloService { @Autowired priv ...
- 洛谷P1983车站分级
洛谷\(P1983\)车站分级(拓扑排序) 目录 题目描述 题目分析 思路分析 代码实现 题目描述 题目在洛谷\(P1983\)上 题目: 一条单向的铁路线上,依次有编号为 \(1, 2, -, ...
- AI换脸必备知识:如何查看显卡型号以及显存大小!
使用Deepfakes(AI换脸) 软件,拼的就是配置,耗的就是时间,考验的是耐心. 配置好了,时间就少了. 所以玩这种软件,硬核需求就是:配置,配置,配置. 我的电脑能跑这个软件么?也是很多新手的 ...