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笔记7-Object类之toString方法和equals方法
位于rt.jar\java\lang\Object.class Object类是所有Java类的根基类(Java中只有一个根基类,C++中有多个).如果在类声明中未使用extends关键字指明其基类, ...
- git的安装教程
团队开发的时候常要用到git来对代码进行管理,平时开发的时候也需要使用git来做一些事情,如给vue项目进行代码编译等等. 那下面我们开始 一.安装和配置环境 首先下载git安装包(去官网下载,htt ...
- TTTTTTTTTTTTTTTT POJ 2723 楼层里救朋友 2-SAT+二分
Get Luffy Out Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8211 Accepted: 3162 Des ...
- LU分解法求逆矩阵 C语言实现
最近在网上找了下,没有找到我想要的C语言版本,找到的也是错误的.故自己写了一个,并进行了相关测试,贴出来分享. 具体的LU分解算法就不细说了,随便找本书就知道了,关键是分解的处理流程,细节特别容易出错 ...
- R_Studio(cart算法决策树)对book3.csv数据用测试集进行测试并评估模型
对book3.csv数据集,实现如下功能: (1)创建训练集.测试集 (2)用rpart包创建关于类别的cart算法的决策树 (3)用测试集进行测试,并评估模型 book3.csv数据集 setwd( ...
- windows基础提权
Window基础提权 提到system权限 甚至让他变成你的肉鸡 我们了解一下windows下面有那些用户 Guests是用户最低的权限 而且一般是被禁用的 User权限也很低 连关机都不行 还有wi ...
- [CSP-S模拟测试]:分组配对(倍增+二分)
题目传送门(内部题108) 输入格式 输入文件第一行为两个正整数$n,M$. 接下来两行,第一行为$n$个正整数$a_1\sim a_n$,其中$a_i$表示编号为$i$的男生的实力值:第二行为$n$ ...
- Filter、Listener、Interceptor、Controller in a Request
从以下程序运行Log 可以看出在一个Request 执行过程中 MyListener>>requestInitialized >>> MyFilter>> ...
- 【每日一包0012】to-camel-case,to-no-case,to-space-case
github地址:https://github.com/ABCDdouyaer/a_pack_per_day_NO.1 to-camel-case 将被其他符号分割的字符串转换为驼峰形式的字符串 用法 ...
- mybatis plus table doesn't exists
使用@TableName 注解即可 实际上就是建立bean与表名的连接