状压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的更多相关文章

  1. HDU 2809 God of War(DP + 状态压缩)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2809 题目大意:给出战神吕布的初始攻击力ATI.防御力DEF.生命值HP.每升一级增加的攻击力In_A ...

  2. HDU 2809 God of War (状压DP)

    God of War Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  3. God of War - HDU 2809(状态压缩+模拟)

    题目大意:貌似是一个游戏,首先给出卢布的攻击,防御,还有血量,再给出每升一级增加的攻击防御还有血量,然后又N个敌人,杀死每个敌人都会得到一些经验,求杀死完所有敌人时剩余的最大血量. 分析:因为敌人比较 ...

  4. hdu 2809(状压dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2809 思路:简单的状压dp,看代码会更明白. #include<iostream> #in ...

  5. 【HDOJ】2809 God of War

    状态DP. /* 2809 */ #include <iostream> #include <queue> #include <cstdio> #include & ...

  6. hdu 4005 The war

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4005 In the war, the intelligence about the enemy is ...

  7. War Chess (hdu 3345)

    http://acm.hdu.edu.cn/showproblem.php?pid=3345 Problem Description War chess is hh's favorite game:I ...

  8. HDU 2435 There is a war

    There is a war Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ...

  9. HDU 4005 The war(双连通好题)

    HDU 4005 The war pid=4005" target="_blank" style="">题目链接 题意:给一个连通的无向图.每条 ...

随机推荐

  1. Oracle中清除BIN$开头的垃圾表的解决办法

    10g的新特性flashback闪回区 在10g中bin开头表示已经删除的放在回收站的表,oracle在删除表时并没有彻底的删除,而是把表放入回收站!purge recyclebin清空回收站即可. ...

  2. 内存管理 & 内存优化技巧 浅析

    内存管理 浅析 下列行为都会增加一个app的内存占用: 1.创建一个OC对象: 2.定义一个变量: 3.调用一个函数或者方法. 如果app占用内存过大,系统可能会强制关闭app,造成闪退现象,影响用户 ...

  3. Android中获取网络数据时的分页加载

    //此实在Fragment中实现的,黄色部分为自动加载,红色部分是需要注意的和手动加载,    蓝色部分是睡眠时间,自我感觉不用写  ,还有就是手动加载时,不知道为什么进去后显示的就是最后一行,求大神 ...

  4. CodeForces 701C They Are Everywhere(map的应用)

    这个题比较好的解决办法,我觉得还是map,map的size可以很快的知道我们选了几个字母,而且可以作为计数器,知道每一个字母出现了多少次, erase函数可以清除掉一个元素. 所以,定义两个指针L和R ...

  5. LightOJ 1370 Bi-shoe and Phi-shoe(欧拉函数)

    题意:题目给出一个欧拉函数值F(X),让我们求>=这个函数值的最小数N,使得F(N) >= F(X); 分析:这个题目有两种做法.第一种,暴力打出欧拉函数表,然后将它调整成有序的,再建立一 ...

  6. 1. Hyper上的CentOS 6.5 网络配置

    在hyper上安装了一个centos系统, 默认安装的是命令行模式,网络默认是不开启的.由于是在虚拟机上安装的centos所以需要现在hyper上新添加一个网络适配器后然后再进行下面的设置: 登陆到r ...

  7. 学习笔记——享元模式Flyweight

    Flyweight模式提供对象的复用. FlyweightFactory类似工厂模式中的工厂,生成对象并提供. 区别在于,享元的工厂会记录生成的对象,当第二次请求到相同的对象时,享元不会再生成一个新对 ...

  8. Linux学习 -- 软件包管理

    1 软件包类型 源码包 脚本安装包  install.sh  不常用 二进制包(rpm包.系统默认包) RedHat -- rpm包 Debian,Ubuntu -- beb包 2 RPM包命令管理 ...

  9. hahah

    ۣۣۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖۖ ...

  10. CF 675 div2C 数学 让环所有值变为0的最少操作数

    http://codeforces.com/contest/675/problem/C 题目大意: 给一个环,标号为1-n,然后能从n回到1.让这个环的值为0,最少需要的操作数是多少? 这道题目呀.. ...