【HDU - 2809】 God of War(状压dp)

题干:

At 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

The input contains at most 20 test cases. 
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

If LvBu is dead output "Poor LvBu,his period was gone." 
Or output the maximum HP left.

Sample Input

100  80  100  5  5  5
2
ZhangFei 95  75  100  100 
XuChu 90  90  100  90100 75 100 5 5 5
1
GuanYu 95 85 100 100

Sample Output

30
Poor LvBu,his period was gone.

 

解题报告:

   状压dp。

AC代码:

#include<bits/stdc++.h>
using namespace std;
struct hero {int att,def,hp,lev;int exp;
} dp[(1<<20)+1];
struct enemy {int att,def,hp,exp;
};
enemy e[25];
int att,def,hp;		
int n;int main() {char str[25];while(~scanf("%d%d%d%d%d%d",&dp[0].att,&dp[0].def,&dp[0].hp,&att,&def,&hp)) {scanf("%d",&n);for(int i=0; i<n; i++) {scanf("%s%d%d%d%d",str,&e[i].att,&e[i].def,&e[i].hp,&e[i].exp);}for(int i=1;i<(1<<20)+1;i++)dp[i].hp=0;dp[0].lev=1;dp[0].exp=0;for(int j=0; j<(1<<n)-1; j++) {if(dp[j].hp<=0)continue;for(int k=0; k<n; k++) {hero temp=dp[j];if((j&(1<<k))!=0)continue;int sub=max(temp.att-e[k].def,1);int sub1=max(e[k].att-temp.def,1);int time=(e[k].hp/sub);if(e[k].hp%sub==0) time--;temp.hp-=time*sub1;if(temp.hp<=0)continue;temp.exp+=e[k].exp;if(temp.exp>=temp.lev*100) {temp.lev++;temp.att+=att;temp.def+=def;temp.hp+=hp;}if(temp.hp>dp[j|(1<<k)].hp)dp[j|(1<<k)]=temp;}}if(dp[(1<<n)-1].hp<=0) {puts("Poor LvBu,his period was gone.");continue;}printf("%d\n",dp[(1<<n)-1].hp);}return 0;
}

总结:

    注意初始化的时候不能直接把dp给memset了,而应该只初始化hp这个成员变量。 

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/441846.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

mysql 优化配置 大批量数据插入_[译] MySQL 最佳实践 —— 高效插入数据

当你需要在 MySQL 数据库中批量插入数百万条数据时&#xff0c;你就会意识到&#xff0c;逐条发送 INSERT 语句并不是一个可行的方法。MySQL 文档中有些值得一读的 INSERT 优化技巧。在这篇文章里&#xff0c;我将概述高效加载数据到 MySQL 数据库的两大技术。LOAD DATA INFILE…

android 移植游戏,Unity游戏移植到Android平台

很多时候不仅需要单纯的运行单个的unity游戏&#xff0c;而是需要将游戏嵌入Android代码中和android其他功能相辅生成一个APP&#xff0c;比如通过android界面的一个按钮来启动一个unity游戏。本文介绍一下主要的过程。1. 将可运行的unity游戏打包为Android project。在Unity界…

code vs 代码格式化排版_23行代码,教你用python实现百度翻译!(建议收藏)

前言&#xff1a;努力折腾的人生虽然不是符合完美生活&#xff0c;但它一定是个很精彩的人生&#xff01;生命在于折腾&#xff0c;正如敲代码一样&#xff0c;你们说是吗&#xff1f;文章主要介绍了用23行python代码实现百度翻译&#xff0c;颇有参考性&#xff0c;喜欢的记得…

mete30是鸿蒙系统么,华为mete30pro什么时候能用上鸿蒙系统?

[其他]华为mete30pro什么时候能用上鸿蒙系统&#xff1f;8957电梯直达huafans01303113614新学乍练发表于 2021-4-21 21:43:19来自&#xff1a;HUAWEI Mate 30 Pro 5G最新回复 2021-4-22 12:10:10华为mete30pro什么时候能用上鸿蒙系统&#xff1f;能有确切的时间吗伊凡爱尔顿已臻…

python运算符中用来计算整商的是什么_零基础学python,看完这篇文章,你的python基础就差不多了...

Python基础语法1. 认识Python1.1 Python 简介Python 的创始人为吉多范罗苏姆&#xff08;Guido van Rossum&#xff09;。Python 的设计目标&#xff1a;一门简单直观的语言并与主要竞争者一样强大开源&#xff0c;以便任何人都可以为它做贡献代码像纯英语那样容易理解适用于短…

华为鸿蒙os系统转正,华为鸿蒙OS系统正式官宣,转正工作提上日程,明年多款终端将使用...

华为鸿蒙OS系统相信很多小伙伴都不陌生&#xff0c;作为国内现如今顶尖的科技企业。华为这些年的发展也是十分迅速的&#xff0c;而再快速的发展过程中。更多的用户对于华为的新款系统也充满了好奇&#xff0c;要知道一款属于国人自己的国产系统。在之前的国内手机上是几乎不存…

map型字段 mongodb_MongoDB极简教程

来源&#xff1a;我没有三颗心脏1.MongDB 简介MongoDB(来自于英文单词“Humongous”&#xff0c;中文含义为“庞大”)是可以应用于各种规模的企业、各个行业以及各类应用程序的开源数据库。作为一个适用于敏捷开发的数据库&#xff0c;MongoDB 的数据模式可以随着应用程序的发展…

html 如何改变图片形状,图形变换的三种方式是什么?

图形变换的三种方式1、平移平移&#xff0c;是指在同一平面内&#xff0c;将一个图形上的所有点都按照某个直线方向做相同距离的移动&#xff0c;这样的图形运动叫做图形的平移运动&#xff0c;简称平移。平移不改变图形的形状和大小。图形经过平移&#xff0c;对应线段相等&am…

Trie树(字典树)详细知识点及其应用

Trie&#xff0c;又经常叫前缀树&#xff0c;字典树等等。它有很多变种&#xff0c;如后缀树&#xff0c;Radix Tree/Trie&#xff0c;PATRICIA tree&#xff0c;以及bitwise版本的crit-bit tree。当然很多名字的意义其实有交叉。 定义 在计算机科学中&#xff0c;trie&#x…

aip格式转化为pdf_python提取pdf文档中的表格数据、svg格式转换为pdf

提取pdf文件中的表格数据原文链接https://www.analyticsvidhya.com/blog/2020/08/how-to-extract-tabular-data-from-pdf-document-using-camelot-in-python/另外还参考了这篇文章https://camelot-py.readthedocs.io/en/master/实现提取pdf文档中的表格数据需要使用camelot模块…

html验证邮箱自动,html5+JavaScript进行邮箱地址验证

html5 网页特效 邮箱地址验证body, input, textarea {font-family: "helvetica", arial, helvetica;}label {display: block;float: left;clear: left;text-align: right;width: 100px;margin-right: 10px;}p { padding: 10px; }fieldset { border: 1px solid #ccc; …

6 rethad 自定义硬盘_图文详解zabbix配置自定义监控项过程

概述今天主要介绍一下zabbix如何去配置自定义监控模板&#xff0c;下面一起来看看吧&#xff01;一、模板1、概念模板(template)&#xff1a;可以应用到主机上的实体(包括监控项、触发器、数据图、图表、监控分类、低级的自动发现规则)的集合。当一个模板被应用到一个主机后&am…

【HDU - 1085 】Holding Bin-Laden Captive! (母函数)

题干&#xff1a; We all know that Bin-Laden is a notorious terrorist, and he has disappeared for a long time. But recently, it is reported that he hides in Hang Zhou of China! “Oh, God! How terrible! ” Don’t be so afraid, guys. Although he hides in a…

html超链接点不了_HTML、CSS、JS都有哪些区别?不看必悔

划重点HTML、CSS、及JS的区别有哪些&#xff1f;在日常学习中&#xff0c;html&#xff0c;css和js我们都学过&#xff0c;起初分不清这三者的区别和联系&#xff0c;随着知识的增长&#xff0c;有了一些体会。看一下这三项技术都是什么&#xff0c;能干什么&#xff1f;web前端…

2019游戏 f1_2019年F1中国大奖赛激情开跑,这款手游带你体验真实F1的魅力

不知不觉&#xff0c;F1中国大奖赛进入第16个年头。你是否还记得2018年的F1中国大奖赛&#xff0c;真是跌宕起伏&#xff0c;红牛队车手里卡多在第三次练习赛中爆缸&#xff0c;之后在车队技师的努力下才赶上排位赛&#xff0c;结果他在正赛时第6位发车&#xff0c;竟然超出对手…

docker jenkins 公钥_代码自动发布docker(20.10.1)+k8s(1.20.1)

PaaS平台Docker版本(20.10.1) 2020-12-15 k8s版本(1.20.1) 2020-12-19代码托管&#xff1a;https://github.com/kubernetes/官方网址&#xff1a;https://kubernetes.io/pod--容器外壳service--不是真正的服务是iptables或ipvs中的规则先创建pod&#xff0c;后创建service…

【HDU - 1272】小希的迷宫 (并查集判环)

题干&#xff1a; 上次Gardon的迷宫城堡小希玩了很久&#xff08;见Problem B&#xff09;&#xff0c;现在她也想设计一个迷宫让Gardon来走。但是她设计迷宫的思路不一样&#xff0c;首先她认为所有的通道都应该是双向连通的&#xff0c;就是说如果有一个通道连通了房间A和B&…

东北育才高中2021年高考成绩查询,东北育才学校国际部2021年招生计划

学校每年的招生计划都会发生变化&#xff0c;并不是一成不变的&#xff0c;所以大家一定要时刻关注招生计划。在报考一所学校的时候&#xff0c;大家要有计划性的选择报考学校&#xff0c;要先去了解学校大概招收多少学生&#xff0c;这样大家在报考学校时候的才能更好地去选择…

html启动word程序,Word工具栏直接启动外部程序

Word工具栏直接启动外部程序互联网 发布时间&#xff1a;2008-10-06 15:13:37 作者&#xff1a;佚名 我要评论从Word工具栏中也能直接启动外部程序&#xff0c;这样操作起来非常方便。我们以从Word启动计算器举例说明。单击“工具”菜单下的“自定义”命令&#xff0c;打…

linux ip brd不一致_3 个方便的命令行网速度测试工具 | Linux 中国

用这三个开源工具检查你的互联网和局域网速度。-- Ben Nuttall能够验证网络连接速度使您可以控制计算机。使您可以在命令行中检查互联网和网络速度的三个开源工具是 Speedtest、Fast 和 iPerf。SpeedtestSpeedtest 是一个旧宠。它用 Python 实现&#xff0c;并打包在 Apt 中&am…