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 ...
随机推荐
- iOS 延迟执行
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(<#delayInSeconds#> * NSEC_PER_SEC)), ...
- hdu1251(字典树)
统计难题(hdu1251) Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others) Tota ...
- escape()、encodeURI()、encodeURIComponent() difference
escape() 方法: 采用ISO Latin字符集对指定的字符串进行编码.所有的空格符.标点符号.特殊字符以及其他非ASCII字符都将被转化成%xx格式的字符编码(xx等于该字符在字符集表里面的编 ...
- nyist 62 笨小熊
http://acm.nyist.net/JudgeOnline/problem.php?pid=62 笨小熊 时间限制:2000 ms | 内存限制:65535 KB 难度:2 描述 笨小熊 ...
- SQL 面向对象
1.面向过程 int a = 10;int b =5;int c = a+b; int r1 = 10;int r2 = 5;double c = r1*r1*3.14 - r2*r2*3.14 缺点 ...
- Android Studio更新升级方法(转)
自从2013 Google I/O大会之后,笔者就将android ide开发工具从eclipse迁移到Android Studio了,android studio一直在更新完善,为了与时俱进,我们当 ...
- eclipse jdk配置
eclipse版本jdk有个默认版本.例如java SE 8[1.8.0_45] 有时候导入一个项目会碰到很奇怪的编译错误.这一般是编译jdk版本导致的. 解决方法:选择任何一个项目-buildpat ...
- emulator-arm.exe 已停止工作、 emulator-x86 已停止工作
问题描述: emulator-arm.exe 已停止工作. emulator-x86 已停止工作.AVD模拟器启动一直黑屏.AVD模拟器启动一直显示andorid界面 解决方法: 1. sdk的安 ...
- windows下快速启动 nginx 和 php-cgi 的两个批处理
这是启动的批处理: set nginx=D:\nginx-1.9.5\ set php=D:\php\ start /MIN %nginx%nginx.exe start /MIN %php%php- ...
- 「ruby/MiniMagick」用MiniMagick处理图片
包的选择和配置 想用RMagick,但据说内存泄露的问题比较厉害,作为替代品MiniMagick不存在内存泄露的问题.而二者都是使用ImageMagick的,所以需要下载并安装ImageMagick. ...