状态DP。

 /* 2809 */
#include <iostream>
#include <queue>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std; #define MAXN 20 typedef struct {
int a, d, h, e;
} hero_t; hero_t hero[MAXN];
int dp[<<MAXN];
int exp[<<MAXN];
int mask[MAXN];
bool visit[<<MAXN];
char name[];
queue<int> Q; int main() {
int n, m, size;
int la, ld, lh;
int ia, id, ih;
int ra, rb, ha, hb;
int i, j, k, tmp;
int s, ss;
int slev, alev, dlev, hlev, sslev; #ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
#endif mask[] = ;
for (i=; i<MAXN; ++i)
mask[i] = (mask[i-]<<); while (scanf("%d%d%d%d%d%d", &la,&ld,&lh, &ia,&id,&ih) != EOF) {
scanf("%d", &n);
for (i=; i<n; ++i)
scanf("%s %d %d %d %d", name, &hero[i].a,&hero[i].d,&hero[i].h,&hero[i].e);
m = <<n;
memset(dp, , sizeof(int)*m);
memset(visit, false, sizeof(bool)*m);
dp[] = lh;
exp[] = ;
Q.push();
visit[] = true;
while (!Q.empty()) {
s = Q.front();
Q.pop();
visit[s] = false;
for (i=; i<n; ++i) {
if (s & mask[i])
continue;
ss = s | mask[i];
// calculate s-state level
slev = exp[s]/;
alev = la+slev*ia;
dlev = ld+slev*id;
// calculate hurt and round
ha = max(, alev-hero[i].d);
hb = max(, hero[i].a-dlev);
ra = (hero[i].h+ha-)/ha;
rb = (dp[s]+hb-)/hb;
if (ra > rb)
continue; // LvBu Lose
exp[ss] = exp[s] + hero[i].e;
sslev = exp[ss]/;
// calculate new hp
tmp = dp[s] - (ra-)*hb + (sslev-slev)*ih;
dp[ss] = max(dp[ss], tmp);
if (visit[ss] == false) {
visit[ss] = true;
Q.push(ss);
}
}
}
if (dp[m-])
printf("%d\n", dp[m-]);
else
printf("Poor LvBu,his period was gone.\n");
} return ;
}

【HDOJ】2809 God of War的更多相关文章

  1. 【HDOJ】3345 War Chess

    简单BFS.注意最后一组数据,每个初始点不考虑周围是否有敌人. /* 3345 */ #include <iostream> #include <cstdio> #includ ...

  2. 【HDOJ】4729 An Easy Problem for Elfness

    其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...

  3. 【HDOJ】【2829】Lawrence

    DP/四边形不等式 做过POJ 1739 邮局那道题后就很容易写出动规方程: dp[i][j]=min{dp[i-1][k]+w[k+1][j]}(表示前 j 个点分成 i 块的最小代价) $w(l, ...

  4. 【HDOJ】【3506】Monkey Party

    DP/四边形不等式 裸题环形石子合并…… 拆环为链即可 //HDOJ 3506 #include<cmath> #include<vector> #include<cst ...

  5. 【HDOJ】【3516】Tree Construction

    DP/四边形不等式 这题跟石子合并有点像…… dp[i][j]为将第 i 个点开始的 j 个点合并的最小代价. 易知有 dp[i][j]=min{dp[i][j] , dp[i][k-i+1]+dp[ ...

  6. 【HDOJ】【3480】Division

    DP/四边形不等式 要求将一个可重集S分成M个子集,求子集的极差的平方和最小是多少…… 首先我们先将这N个数排序,容易想到每个自己都对应着这个有序数组中的一段……而不会是互相穿插着= =因为交换一下明 ...

  7. 【HDOJ】【3415】Max Sum of Max-K-sub-sequence

    DP/单调队列优化 呃……环形链求最大k子段和. 首先拆环为链求前缀和…… 然后单调队列吧<_<,裸题没啥好说的…… WA:为毛手写队列就会挂,必须用STL的deque?(写挂自己弱……s ...

  8. 【HDOJ】【3530】Subsequence

    DP/单调队列优化 题解:http://www.cnblogs.com/yymore/archive/2011/06/22/2087553.html 引用: 首先我们要明确几件事情 1.假设我们现在知 ...

  9. 【HDOJ】【3068】最长回文

    Manacher算法 Manacher模板题…… //HDOJ 3068 #include<cstdio> #include<cstring> #include<cstd ...

随机推荐

  1. Haskell 差点儿无痛苦上手指南

    趁着自己重装Linux 虚拟机的机会,把安装 haskell 的过程记录一下,顺便帮那些还犹豫徘徊在haskell门外的读者入门. 基本概念: Haskell : 是一门通用函数式语言,差点儿能够进行 ...

  2. 网络编程---(数据请求+slider)将网络上的大文件下载到本地,并打印其进度

    网络编程---将网络上的大文件下载到本地,并打印其进度. 点击"開始传输"button.将网络上的大文件先下载下来,下载完毕后,保存到本地. UI效果图例如以下: watermar ...

  3. [PWA] 9. Service worker registerion && service work's props, methods and listeners

    In some rare cases, you need to ask user to refresh the browsser to update the version. Maybe becaus ...

  4. Android设置虚线、圆角、渐变

    有图又真相,先上图再说. 点击效果: 设置虚线: <?xml version="1.0" encoding="utf-8"?> <shape  ...

  5. RT:How HTTP use TCP connection

    In HTTP/0.9 (not used anymore), each request uses a separate TCP connection, and the end of a respon ...

  6. Java基础知识强化之集合框架笔记13:Collection集合存储学生对象并遍历

    1. Collection集合存储学生对象并遍历: 需求:存储自定义对象并遍历Student(name,age) 分析: (1)创建学生类 (2)创建集合对象 (3)创建学生对象 (4)把学生对象添加 ...

  7. CentOS7搭建SAMBA服务器实现与WIN10匿名共享文件

    1.安装SAMBA yum -y install samba samba-client samba-common 2.修改文件打开数 vi /etc/security/limits.conf 最后添加 ...

  8. iOS报错Expected selector for Objective-C method

    这个报错非常恶心:原因竟然是在导入头文件的地方多写了一个"+"号,可能问题在一个文件,报错在另一个文件

  9. sql 学习笔记 p46

    交换行 update tab1 set c1=c2,c2=c1  .说明sql是临时表的存储,在查询出来的结果为决定前,可以随意操纵临时表中的列 update tab set c1=c1+(selec ...

  10. (转)Mac OS X中配置Apache

    我使用的Mac OS X版本是10.8.2,Mac自带了Apache环境. 启动Apache 设置虚拟主机 启动Apache 打开“终端(terminal)”,输入 sudo apachectl -v ...