这题上来我是没有思路的。因为目标值关涉到的因素太多而直接枚举的复杂度又太高。
目标值由两部分合成,一部分是队员的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 ;
}