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="">题目链接 题意:给一个连通的无向图.每条 ...
随机推荐
- python2.x 使用protobuf
1.在windows下配置protobuf 1.1 下载对应的包,包含两个:protoc.exe和源码文件(protoc也可以自己生成) 下载地址1 --- google code最近在迁移,也许以后 ...
- WPF InkCanvas 画图 基础使用教程
大家好,由于很多原因,我有很长一段时间没有在 CSDN 上分享我的学习成果了,如今终于可以回归分享之路了. 之前在做一个项目的时候,想在一个区域里绘制自己的图形,于是上网搜索资料,无意中找到了 Ink ...
- jquery 限制字数 显示输入字数 插件
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 最短路<dijk>
题意: 有n个城市,有m条路,给出每条路的出发和结束的城市及长度,求从第一个城市到最后一个城市的最短路.按格式输出. power oj 2443 题解: 标准dijk算法. #include<c ...
- MFC添加背景图片三种方法
方法一: 1.声明成员变量CBrush m_brush;2.在InitDialog中添加代码: ? CBitmap bmp; bmp.LoadBitmap(IDB_BITMAP1); //IDB_B ...
- Android Studio中有没有类似于Eclipse中的ctrl+2+L的快捷键? \Android Studio快捷键之代码提示
问:Android Studio中有没有类似于Eclipse中的ctrl+2+L的快捷键? 答:有,as中的快捷键是Ctrl+Alt+V AndroidStudio和Eclipse常用快捷键对比 功能 ...
- html5中拨打电话代码
<a href="tel:18600000000">给我打电话</a> <a href="sms:18600000000"&g ...
- hprof网络连接
demo/jvmti/hprof/tt/manual.htmlnc -l -k 12321 java -agentpath:./demo/jvmti/hprof/lib/libhprof.so=net ...
- 4-20ma电流信号转0-5v()
源:4-20ma电流信号转0-5v 电压转电流电路原理图(0-5V转4-20mA) 4mA-20mA转0-5v电路问题,LM324一直输出10V
- jQuery笔记(1)
jQuery 是一个类库 拥有众多js函数的类库 jQuery 大大简化了js的书写代码,看的舒服,用的爽. jQuery 是一个数组,它能够隐性的遍历. 比如 ${"button" ...