状压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. 快学Scala-第五章 类

    知识点: 1.简单类和无参方法 class Counter { private var value = 0 //必须初始化字段 def increment() { value += 1} //方法默认 ...

  2. 转:如何让LoadRunner实现多个场景运行?

    场景分析: 有3个不同的场景,分别为搜索,下载,上传,其中3个场景执行顺序为按照搜索->下载->上传流程操作:哪么如何让Loadrunner中如何实现多个场景运行: 方法1:利用Loadr ...

  3. FileReader和BufferedReader的区别

    1.FileReader不能一行行读 FileReader fr = null; try { fr = new FileReader(new File(path)); StringBuffer str ...

  4. jvisualvm

    f the fonts used by VisualVM are hard to read, switching the LaF might help.  Try for example  'visu ...

  5. 苹果充电器USB端的识别电阻的设置

    苹果为充电器定义了3种充电电流,分别是0.5A/1A/2.1A.具体是由3种不同的电阻组合来实现的.当苹果的设备ipad,iphone,ipod接入USB口充电器时,会先检测USB D+和D-上的电压 ...

  6. PowerDesigner设置线风格(直线,折线。。。)

    PowerDesigner中的绘图功能真是不敢恭维. 1.修改显示设置 Tools-->Display Preferences 这里有很多表现设置,我们需要的在Format菜单下. 点Modif ...

  7. ecostore搜索注意事项

    ecostore搜索时会把特殊字符转换为相应的文字 如 洋河480ml_52°天之蓝 进行html url编码时会把_(下划线)转换成%25xia%25(%25对应的ascii是%) 搜索时会把%.x ...

  8. jdb

    http://herongyang.com/jtool/jdb.html http://www.rhcedan.com/2010/06/22/killing-a-java-thread/ 用处:上去杀 ...

  9. Delphi xe7并行编程快速入门(转)

    源:http://blog.csdn.net/henreash/article/details/41315183 现在多数设备.计算机都有多个CPU单元,即使是手机也是多核的.但要在开发中使用多核的优 ...

  10. phpstrom 快捷键

    常用的PHPStorm快捷键:ctrl+j 插入活动代码提示ctrl+alt+t 当前位置插入环绕代码alt+insert 生成代码菜单ctrl+q 查看代码注释ctrl+d 复制当前行ctrl+y ...