HDU 2809 God of War
状压DP。我认为是数据水了,用打死了哪几只作为状态,AC代码只需要保存当前状态的最大血量,完全没有考虑攻击力大小。
个人认为正确DP应该这样的:dp[状态][等级],但这样写不能AC,时间复杂度会很大,但答案应该是正确的。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<iostream>
using namespace std; struct X
{
int HP;
int ATI;
int DEF;
int e;
int lv;
} dp[( << ) + ], A[]; int In_ATI, In_DEF, In_HP;
int ATI, DEF, HP;
int n;
int base[]; int MAX(int a, int b)
{
if (a>b) return a;
return b;
} void read()
{
scanf("%d", &n);
for (int i = ; i<n; i++)
{
string name;
cin >> name;
scanf("%d%d%d%d", &A[i].ATI, &A[i].DEF, &A[i].HP, &A[i].e);
}
} void init()
{
dp[].ATI = ATI, dp[].DEF = DEF, dp[].HP = HP;
dp[].e = , dp[].lv = ; for (int i = ; i<( << n); i++) dp[i].HP = -;
} int f(int num1, int num2)
{
int A1 = MAX(, dp[num1].ATI - A[num2].DEF);
int A2 = MAX(, A[num2].ATI - dp[num1].DEF); int HP1 = dp[num1].HP;
int HP2 = A[num2].HP; int tot1, tot2;
if (HP2%A1 == ) tot1 = HP2 / A1;
else tot1 = HP2 / A1 + ; if (HP1%A2 == ) tot2 = HP1 / A2;
else tot2 = HP1 / A2 + ; if (tot1 <= tot2) return HP1 - A2*(tot1 - ); //返回吕布打完后的血量
return -; //返回吕布被打死
} void work()
{
for (int i = ; i<( << n); i++)
{
int tot = , tmp = i;
while (tmp) base[tot++] = tmp % , tmp = tmp / ; for (int j = ; j<tot; j++)
{
if (base[j])
{
int pre = i - ( << j);
if (dp[pre].HP == -) continue; int lx = f(pre, j);
if (lx == -) continue; int hp = lx;
int e = dp[pre].e + A[j].e;
int lv = dp[pre].lv;
int ati = dp[pre].ATI;
int def = dp[pre].DEF; if (e >= * dp[pre].lv)
{
hp = hp + In_HP;
ati = ati + In_ATI;
def = def + In_DEF;
lv++;
} if (hp>dp[i].HP)
{
dp[i].e = e;
dp[i].lv = lv;
dp[i].HP = hp;
dp[i].ATI = ati;
dp[i].DEF = def;
}
}
}
} if (dp[( << n) - ].HP == -) printf("Poor LvBu,his period was gone.\n");
else printf("%d\n", dp[( << n) - ].HP);
} int main()
{
while (~scanf("%d%d%d%d%d%d", &ATI, &DEF, &HP, &In_ATI, &In_DEF, &In_HP))
{
read();
init();
work();
}
return ;
}
HDU 2809 God of War的更多相关文章
- HDU 2809 God of War(DP + 状态压缩)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2809 题目大意:给出战神吕布的初始攻击力ATI.防御力DEF.生命值HP.每升一级增加的攻击力In_A ...
- HDU 2809 God of War (状压DP)
God of War Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- God of War - HDU 2809(状态压缩+模拟)
题目大意:貌似是一个游戏,首先给出卢布的攻击,防御,还有血量,再给出每升一级增加的攻击防御还有血量,然后又N个敌人,杀死每个敌人都会得到一些经验,求杀死完所有敌人时剩余的最大血量. 分析:因为敌人比较 ...
- hdu 2809(状压dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2809 思路:简单的状压dp,看代码会更明白. #include<iostream> #in ...
- 【HDOJ】2809 God of War
状态DP. /* 2809 */ #include <iostream> #include <queue> #include <cstdio> #include & ...
- hdu 4005 The war
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4005 In the war, the intelligence about the enemy is ...
- War Chess (hdu 3345)
http://acm.hdu.edu.cn/showproblem.php?pid=3345 Problem Description War chess is hh's favorite game:I ...
- HDU 2435 There is a war
There is a war Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ...
- HDU 4005 The war(双连通好题)
HDU 4005 The war pid=4005" target="_blank" style="">题目链接 题意:给一个连通的无向图.每条 ...
随机推荐
- sql/plus 常用操作
一.sys用户和system用户Oracle安装会自动的生成sys用户和system用户(1).sys用户是超级用户,具有最高权限,具有sysdba角色,有create database的权限,该用户 ...
- curl file_get_contents fsockopen
三种处理的方式: curl file_get_contents fsockopen fsockopen 是比较底层的调用,属于网络系统的socket调用,而curl经过的包装支 ...
- cmd下载文件
进入cmd 输入ftp 192.168.1.200 然后按照提示输入用户名和密码 cd 进入要下载的目录 dir 看操作权限 lcd查看本地要装下载文件的目录 prompt关闭交互模式 mget da ...
- hdu 1535 Invitation Cards(SPFA)
Invitation Cards Time Limit : 10000/5000ms (Java/Other) Memory Limit : 65536/65536K (Java/Other) T ...
- hdu 1180诡异的楼梯(bfs)
诡异的楼梯 Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other) Total Submis ...
- jz2440 环境搭建遇到的问题
已解决:
- Oracle Sql优化之lead,lag分析函数
1.表中有四个字段:人员编号,开始时间,结束时间,类型,数据ID,需要实现如下需求 a.当类型为-1时,丢弃该记录 b.当类型为-1时,且前一行结束时间为null,当前行的开始时间-1作为前一行的结束 ...
- linux常用命令 、查看日志、web排查
linux常用命令 ps aux|grep xxx (比如 ps aux|grep tomcat ps aux|grep tomcat-portalvip ps aux|grep nginx 等) r ...
- 一个简单的基于HTTP协议的屏幕共享应用
HTTP协议可以能是应用层协议里使用最广泛并且用途最多样的一个了.我们一般使用HTTP协议来浏览网页,但是HTTP协议还用来做很多其它用途.对开发人员来讲很常见的一种就是用HTTP协议作为各种版本控制 ...
- struts2语法--error页面如何捕获?
如果地址栏输入了不带后缀或者action为后缀, 不存在的页面跳转到error.jsp: struts.xml配置" <package name="default" ...