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 ...
随机推荐
- Java基础——集合框架(待整理)
ArrayList 和 和 Vector 的区别 从代码的最终的操作形式上可以发现,代码的输出结果与之前是一样的,而且没有区别,但是两者的区别还在于其内部的组成上. No. 区别点 Vector Ve ...
- 【leetcode】1258. Synonymous Sentences
题目如下: Given a list of pairs of equivalent words synonyms and a sentence text, Return all possible sy ...
- Python 异常处理Ⅳ
异常的参数 一个异常可以带上参数,可作为输出的异常信息参数. 你可以通过except语句来捕获异常的参数,如下所示: 变量接收的异常值通常包含在异常的语句中.在元组的表单中变量可以接收一个或者多个值. ...
- T级别视频上传解决方案
之前仿造uploadify写了一个HTML5版的文件上传插件,没看过的朋友可以点此先看一下~得到了不少朋友的好评,我自己也用在了项目中,不论是用户头像上传,还是各种媒体文件的上传,以及各种个性的业务需 ...
- 【LOJ2604】「NOIP2012」开车旅行
[题目链接] [点击打开链接] [题目大意] 从西到东的坐标轴\([1,n]\)上有\(n\)个海拔互不相同的城市,每两个城市之间的距离定义为\(dis(i,j)=|h_i-h_j|\) 小\(A\) ...
- 51Nod 1005 有负数的高精度加法
51Nod是个好地方啊 题意 51Nod基础题第二题,高精度加法,可能有负数. 解题 如果按照一般的高精度,我们发现要分情况讨论,还要写高精度加法和减法,代码实现有点烦.而初中数学里说,省略加号的和. ...
- [BZOJ5249][九省联考2018]IIIDX:线段树+贪心
分析 GXZlegend orz 构造出一组合法的解并不是难事,但是我们需要输出的是字典序最大的解. 字典序最大有另一种理解方式,就是让越小的数尽量越靠后. 我们从树的根结点出发,从1开始填数,构造出 ...
- 使用keil生成bin文件
相关文件 下载http://pan.baidu.com/share/link?shareid=478269&uk=1107426113 使用kei自带的工具的话是 打开Options f ...
- Android_(服务)Vibrator振动器
Vibrator振动器是Android给我们提供的用于机身震动的一个服务,例如当收到推送消息的时候我们可以设置震动提醒,也可以运用到游戏当中增强玩家互动性 运行截图: 程序结构 <?xml ve ...
- Kotlin 1 新运算符
新运算符: “..” ,"in ","!in" ,"downto","step"注意: 1. 关系运算符的优先级低于算术 ...