hdu4924 Football Manager
这题上来我是没有思路的。因为目标值关涉到的因素太多而直接枚举的复杂度又太高。
目标值由两部分合成,一部分是队员的CA和与PA和,另一部分是队员之间的relationship。
前者是简单的代数累加,而后者显然才是本题需要解决的问题。
由于relatioship由具体的出场方案所决定,因此不知道哪些队员上场就不可能知道它的值是多少,并且估算它有用的上下界也是困难的。
因此只能想到枚举,首先枚举哪些队员上场(这一步的复杂度就非常高,如果按题目给的数据范围对于强数据是根本不可能通过的)。
于是第二部分的值就确定了,现在只需要解决第一部分的求值。
这一部分不需要暴力枚举(如果仍然枚举仅在此处最坏情况下复杂度也会上万),因为既然是代数和的累加必然可以找到不同状态之间的联系。
对于某个特定的队员只会被任命在4个位置中的一个,现在方案只会是内部队员出场位置的调整。那么我们可以想到dp,通过枚举-更新的方法寻求最佳方案。
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <ctime>
#pragma comment(linker, "/STACK:102400000,102400000")
#define lson (u << 1)
#define rson (u << 1 | 1)
#define rep(i, a, b) for(i = a; i < b; i++)
#define repi(i, a, b, c) for(i = a; i < b; i += c)
#define cls(i, j) memset(i, j, sizeof i);
using namespace std;
typedef long long ll;
const double eps = 1e-;
const double pi = acos(-1.0);
const int maxn = + ;
const int maxm = ;
const int inf = 0x3f3f3f3f;
const ll linf = 0x3fffffffffffffff;
const ll mid = 1e9 + ; struct P{
int id, o[];
int c[], p[], cmax;
bool operator < (const P &rhs) const{
return cmax > rhs.cmax;
}
}a[maxn]; int n, m;
int idx[maxn];
int g[maxn][maxn]; int f(char ch){
switch(ch){
case 'G' : return ;
case 'D' : return ;
case 'M' : return ;
case 'S' : return ;
}
} int select[];
int l[]; struct Point{
int x, y;
Point(int x = , int y = ) : x(x), y(y) {}
bool operator < (const Point &rhs){
return x < rhs.x || x == rhs.x && y < rhs.y;
}
Point operator + (const Point &rhs){
return Point(x + rhs.x, y + rhs.y);
}
bool operator == (const Point &rhs){
return x == rhs.x && y == rhs.y;
}
}dp[][][][];//i, 0, 1, 2 Point ANS, INF = Point{-inf, -inf}; Point max(Point lhs, Point rhs) { return lhs < rhs ? rhs : lhs; } void update(int u, int kind, int n0, int n1, int n2){
Point dest = dp[u][n0][n1][n2] + Point{a[select[u]].c[kind], a[select[u]].p[kind]};
Point *src = &dp[u + ][n0 + ( == kind)][n1 + ( == kind)][n2 + ( == kind)];
(*src) = max((*src), dest);
} void cal(){
int cnt[];
cls(cnt, );
int i, j, k, u, v;
rep(i, , ) rep(j, , ) if(a[select[i]].o[j]) ++cnt[j];
rep(i, , ) if(cnt[i] < l[i]) return;
int ca = ;
rep(i, , ) rep(j, i, ){
int x = a[select[i]].id, y = a[select[j]].id;
ca += g[x][y];
if(i != j) ca += g[y][x];
}
int high = ca;
rep(i, , ) high += a[select[i]].cmax;
if(high < ANS.x) return;//curcial pruning
rep(i, , ) rep(j, , cnt[] + )
rep(k, , cnt[] + ) rep(u, , cnt[] + ) dp[i][j][k][u] = INF;
dp[][][][] = Point{, };
rep(i, , ) rep(j, , l[] + ) rep(k, , l[] + ) rep(u, , l[] + ){
if(dp[i][j][k][u] == INF) continue;
rep(v, , ) if(a[select[i]].o[v]) update(i, v, j, k, u);
}
ANS = max(ANS, Point(ca, ) + dp[][l[]][l[]][l[]]);
} void fswap(int x, int y){
int i;
rep(i, , n) swap(a[i].c[x], a[i].c[y]), swap(a[i].p[x], a[i].p[y]), swap(a[i].o[x], a[i].o[y]);
swap(l[x], l[y]);
} void dfs(int pos, int num){
//num::how many palyers has been chosen
if(num == ){
cal();
return;
}
if(pos == n || n - pos + num < ) return;
select[num] = pos;
dfs(pos + , num + );
dfs(pos + , num);
} void solve(){
ANS = INF;
dfs(, );
if(ANS == INF) puts("Poor Manager!");
else printf("%d %d\n", ANS.x, ANS.y);
} int main(){
//freopen("in.txt", "r", stdin);
int T;
scanf("%d", &T);
char buf[];
while(T--){
scanf("%d", &n);
int i, j, tem;
rep(i, , n) rep(j, , ) a[i].o[j] = ;
rep(i, , n){
a[i].cmax = -inf;
scanf("%d%d", &a[i].id, &tem);
rep(j, , tem){
scanf("%s", buf);
int tem1 = f(buf[]);
a[i].o[tem1] = ;
scanf("%d%d", &a[i].c[tem1], &a[i].p[tem1]);
a[i].cmax = max(a[i].cmax, a[i].c[tem1]);
}
}
cls(g, );
sort(a, a + n);
scanf("%d", &m);
rep(i, , m){
int u, v, w;
scanf("%d%d%s%d", &u, &v, buf, &w);
g[u][v] = (buf[] == 'D' ? - : ) * w;
}
scanf("%d-%d-%d", &l[], &l[], &l[]);
l[] = - l[] - l[] - l[];
int maxp = , maxv = l[];
rep(i, , ) if(l[i] > maxv) maxv = l[i], maxp = i;
if(maxp != ) fswap(, maxp);
solve();
}
return ;
}
hdu4924 Football Manager的更多相关文章
- WOJ 124. Football Coach 网络流
Problem 1124 - Football Coach Description It is not an easy job to be a coach of a football team. Th ...
- CodeForces-1244C-The Football Season-思维
The football season has just ended in Berland. According to the rules of Berland football, each matc ...
- Windows下Redis缓存服务器的使用 .NET StackExchange.Redis Redis Desktop Manager
Redis缓存服务器是一款key/value数据库,读110000次/s,写81000次/s,因为是内存操作所以速度飞快,常见用法是存用户token.短信验证码等 官网显示Redis本身并没有Wind ...
- 如何重新注册VMware Update Manager(VUM)至vCenter Server中
在VMware的vSphere化境中,VUM的角色相当于Windows 环境中的WSUS(Windows 更新服务器),可以批量,自动化的完成所管辖ESXi主机的大版本迁移,小版本升级的任务,深受管理 ...
- 使用tomcat manager 管理和部署项目
在部署tomcat项目的时候,除了把war文件直接拷贝到tomcat的webapp目录下,还有一种方法可以浏览器中管理和部署项目,那就是使用tomcat manager. 默认情况下,tomcat m ...
- Ubuntu管理开机启动服务项 -- 图形界面的Boot-up Manager
有时学习时安装的服务太多,比如mysql.mongodb.redis.apache.nginx等等,它们都是默认开机启动的,如果不想让它们开机启动,用到时再自己手工启动怎么办呢? 使用sysv-rc- ...
- Android SDK Manager 更新代理配置
转自:http://www.cnblogs.com/tao560532/p/4483067.html 出现问题: 消除SDK更新时,有可能会出现这样的错误:Download interrupted: ...
- 通读AFN①--从创建manager到数据解析完毕
流程梳理 今天开始会写几篇关于AFN源码解读的一些Blog,首先要梳理一下AFN的整体结构(主要是讨论2.x版本的Session访问模块): 我们先看看我们最常用的一段代码: AFHTTPSessio ...
- SQL Server恢复软件SysTools SQL Recovery/SysTools SQL Server Recovery Manager
SQL Server恢复软件SysTools SQL Recovery/SysTools SQL Server Recovery Manager http://www.systoolsgroup.co ...
随机推荐
- 连接sql server数据库的两种方式
class DB { private static SqlConnection conn; public static SqlConnection getConn() { //conn = n ...
- Redis 存储原理
- Spring shiro使用
maven依赖: <dependency> <groupId>commons-collections</groupId> <artifactId>com ...
- zabbix添加邮件报警机制
zabbix添加邮件报警机制 作者:尹正杰 还记得之前跟大家聊过的一个如何监控一个目录的话题吗?我们虽然监控出来数据了,也有数据了,但是,只是监控也没有用啊~因为我们不能24小时盯着屏幕然后 出了事情 ...
- [Reprint]C++函数前和函数后加const修饰符区别
c++中关于const的用法有很多,const既可以修饰变量,也可以函数,不同的环境下,是有不同的含义.今天来讲讲const加在函数前和函数后面的区别.比如: 01 #include<iostr ...
- php导入导出
首先:下载好PHPExcel类库文件 视图层: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ...
- 1.表单中 get与post提交方法的区别?
get是发送请求HTTP协议通过url参数传递进行接收,而post是实体数据,可以通过表单提交大量信息. get是从服务器上获取数据,post是向服务器传送数据. GET方式提交的数据最多只能有102 ...
- struts_24_基于XML校验的规则、特点
当为某个action提供了ActionClassName-validation.xml和ActionClassName-ActionName-validation.xml两种规则的校验文件时,系统按下 ...
- Android中实现app版本更新
1,获取本地程序apk版本,并开启服务(下面这段代码一般在主Activity中的onCreate()方法中执行的,并开启后台服务下载新版本的apk) //获取apk包文件的管理者对象 PackageM ...
- 实验一 操作系统模仿cmd
实验一.命令解释程序的编写 专业:商软(2)班 姓名:王俊杰 学号:201406114252 一. 实验目的 (1)掌握命令解释程序的原理: (2)掌握简单的DOS调用方法: (3 ...