Problem descriptionfootball manager is a series of football management simulation games developed by Sports Interactive and published by Sega. in this game, you will play a role of a football club manager and conducting your team to chase championship titles. as a football team manager, you need to take responsibilities for tactics developing, training arrangements, on-pitch commanding, player trading, etc. one of the most important things is to select your starting line-up.
According to the rules of football matches, there shocould be 11 players in your starting line-up, where one of them must be a goalkeeper. besides the goalkeeper (Gk), There're three classes of positions: Defender (DF), midfielder (MF), and striker (ST ).
When a manager is selecting his starting line-up, he usually determines the formation first. the football formation is usually noted like "4-4-2" "4-5-1" "4-3-3", etc. for example, the "4-5-1" formation denotes that there are 4 defenders, 5 midfielders and 1 striker. note that every player has his preferred positions, and they will always refuse to appear at positions he does not prefer, while some excellent players may be qualified for several positions. for example, C. ronaldo can play as both a striker and a midfielder.
In the game, players have two important attributes
For each of his preferred positions: Ca (current ability) and PA (potential ability ). the CA of the line-up is defined as the sum of the 11 players 'Ca in the formation. similar to CA, the PA of the line-up equals to the sum of 11 players' Pa. then your task is to select the proper players to reach maximum Ca of your line-up. when a tie occurs, the one of maximum PA is required.
Beyond these requirements and limits, the relationships between players also make sense to the CA of your line-up. every player may like or dislike some of his teammates. when he and the one he likes are both on the pitch, the CA of the line-up will be increased by a specific value. on the contrary, when someone and his disliked player occurs on the pitch concurrently, the line-up's CA will be decreased. be careful that the like and dislike relationships between players are unidirectional. not surprisingly, plane. gao likes Messi very much while Messi may not know plane. gao at all.
Inputthe input contains multiple test cases. The first line of input gives the number of test cases T (1 <= T <= 20 ).
For each test case, the first line contains an integer N (1 <= n <= 20), the total number of players in your team.
Each of the following n lines describe a player in the following format:
<Squadnum> <positionnum> <pos1> <A1> <pa1> <pos2> <Ca 2> <pa2>... <posnum> <canum> <panum>
Here:
<Squadnum> denotes the player's unique squad number (between 1 and 99, aggressive ).
<Positionnum> denotes the number of positions he preferred.
<Pos1> <pos2>... <posnum> are strings chosen in {GK, DF, MF, St}, denoting all his preferred positions.
<Cai> denotes his CA at <posi>.
<Pai> denotes his Pa at <posi>.
(0 <= | P ai |, | c ai |<= 1000,
Note p A and CA can be negative here.)
After the description of the player list, the following line will give an integer m (0 <= m <= n (n-1 )), which indicates the number of relationships between the teammates. then each of the following M lines is shown in the following format:
<Squadnuma> <squadnumb> like/dislike <value>
Here:
<Squadnuma> denotes Player A's squad number.
<Squadnumb> denotes Player B's squad number.
Like/dislike denotes the property of the relationship.
<Value> denotes that when both of them appear in your starting line-up, the CA of line-up will be increased/decreased by value (0 <= value <= 100 ).
No two relationships of the same pair of teammates will occur.
The last line of each test case shows the formation that you have determined. We guarantee that the formation is legal.
You may take the sample for more details.
Outputfor each test case, You shoshould output two integers in a line, the best Ca and Pa of your line-up. if you can even not round up your line-up, please output "poor manager!" (Without quotes)
Sample Input
2151 1 GK 150 1602 1 DF 150 1603 1 DF 150 1604 1 DF 150 1605 1 DF 150 1606 1 MF 150 1607 1 MF 150 1608 1 MF 150 1609 1 ST 150 16010 1 MF 150 16011 1 ST 150 16012 1 GK 130 15013 1 DF 130 15014 1 MF 130 15015 1 ST 130 150215 9 Like 102 13 Dislike 204-4-2111 1 GK 150 1602 1 DF 150 1603 1 DF 150 1604 1 DF 150 1605 1 DF 150 1606 1 MF 150 1607 1 MF 150 1608 1 MF 150 1609 1 ST 150 16010 1 MF 150 16011 1 ST 150 16004-3-3
Sample output
1650 1760Poor Manager!
Authorbupt
Source2014 multi-university training contest 6
Train of Thought: first, DFS lists all 11 members selected as team members. If the largest number of members is not large enough for ansc or cannot constitute a football team, it will return directly, then use DP to obtain the maximum value.
# Include <stdio. h> # define INF 99999999 # define max (A, B) (A> B? A: B) struct s {int C [4], p [4], MX; bool flag [4];} node [20]; int N, hash [100], add [20] [20], a, B, c, ansc, ANSP, DF, MF, St, GK, attach, DPC [13] [3] [13] [13], DPP [13] [3] [13] [13], Sel [13]; void DFS (INT now, int CNT) {If (CNT = 11) {int I, J, K, L, MX; attach = 0; for (I = 0; I <11; I ++) for (j = 0; j <11; j ++) Attach + = add [sel [I] [sel [J]; MX = 0; for (I = 0; I <11; I ++) mx + = node [sel [I]. MX; If (mx + attach <ansc) return; // optimized pruning GK = df = mf = sT = 0; for (I = 0; I <11; I ++) {If (node [sel [I]. flag [0]) GK ++; If (node [sel [I]. flag [1]) dF ++; If (node [sel [I]. flag [2]) MF ++; If (node [sel [I]. flag [3]) ST ++;} If (GK <1 | DF <A | MF <B | st <c) return; // cannot constitute a football team for (I = 0; I <= 11; I ++) for (j = 0; j <= 1; j ++) for (k = 0; k <= A; k ++) for (L = 0; L <= B; l ++) DPC [I] [J] [k] [l] =-INF; DPC [0] [0] [0] [0] = DPP [0] [0] [0] = 0; for (I = 0; I <11; I ++) {for (j = 0; j <= 1; j ++) {for (k = 0; k <= A; k ++) {for (L = 0; L <= B; l ++) {If (DPC [I] [J] [k] [l]! =-INF) {If (node [sel [I]. flag [0]) {If (DPC [I + 1] [J + 1] [k] [l] <DPC [I] [J] [k] [l] + node [sel [I ]. c [0]) {DPC [I + 1] [J + 1] [k] [l] = DPC [I] [J] [k] [l] + node [sel [I]. c [0]; DPP [I + 1] [J + 1] [k] [l] = DPP [I] [J] [k] [l] + node [sel [I]. P [0];} else if (DPC [I + 1] [J + 1] [k] [l] = DPC [I] [J] [k] [l] + node [sel [i]. c [0]) {DPP [I + 1] [J + 1] [k] [l] = max (DPP [I] [J] [k] [l] + node [sel [I ]. P [0], DPP [I + 1] [J + 1] [k] [l]);} If (node [sel [I]. flag [1]) {If (DPC [I + 1] [J] [K + 1] [l] <DPC [I] [J] [k] [l] + node [sel [I]. c [1]) {DPC [I + 1] [J] [k + 1] [l] = DPC [I] [J] [k] [l] + node [sel [I]. c [1]; DPP [I + 1] [J] [k + 1] [l] = DPP [I] [J] [k] [l] + node [sel [I]. P [1];} else if (DPC [I + 1] [J] [k + 1] [l] = DPC [I] [J] [k] [l] + node [sel [i]. c [1]) {DPP [I + 1] [J] [k + 1] [l] = max (DPP [I] [J] [k] [l] + node [sel [I ]. P [1], DPP [I + 1] [J] [k + 1] [l]) ;}} if (node [sel [I]. flag [2]) {If (DPC [I + 1] [J] [k] [L + 1] <DPC [I] [J] [k] [l] + node [sel [I ]. c [2]) {DPC [I + 1] [J] [k] [L + 1] = DPC [I] [J] [k] [l] + node [sel [I]. c [2]; DPP [I + 1] [J] [k] [L + 1] = DPP [I] [J] [k] [l] + node [sel [I]. P [2];} else if (DPC [I + 1] [J] [k] [L + 1] = DPC [I] [J] [k] [l] + node [sel [i]. c [2]) {DPP [I + 1] [J] [k] [L + 1] = max (DPP [I] [J] [k] [l] + node [sel [I ]. P [2], DPP [I + 1] [J] [k] [L + 1]) ;}} if (node [sel [I]. flag [3]) {If (DPC [I + 1] [J] [k] [l] <DPC [I] [J] [k] [l] + node [sel [I]. c [3]) {DPC [I + 1] [J] [k] [l] = DPC [I] [J] [k] [l] + node [sel [I]. c [3]; DPP [I + 1] [J] [k] [l] = DPP [I] [J] [k] [l] + node [sel [I]. P [3];} else if (DPC [I + 1] [J] [k] [l] = DPC [I] [J] [k] [l] + node [sel [I] ]. c [3]) {DPP [I + 1] [J] [k] [l] = max (DPP [I] [J] [k] [l] + node [sel [I]. P [3], DPP [I + 1] [J] [k] [l]) ;}}}} DPC [11] [1] [a] [B] + = attach; If (ansc <DPC [11] [1] [a] [B]) ansc = DPC [11] [1] [a] [B], ANSP = DPP [11] [1] [a] [B]; else if (ansc = DPC [11] [1] [a] [B]) ANSP = max (DPP [11] [1] [a] [B], ANSP); return;} If (now> = n | CNT + N-Now <11) Return; SEL [CNT] = now; DFS (now + 1, CNT + 1); // select DFS (now + 1, CNT); // do not select} int main () {int T, I, j, T, ID, Val; char s [5]; scanf ("% d", & T); While (t --) {scanf ("% d", & N); for (I = 0; I <n; I ++) {scanf ("% d", & T ); hash [T] = I; for (j = 0; j <4; j ++) node [I]. flag [J] = 0; node [I]. MX =-INF; scanf ("% d", & T); While (t --) {scanf ("% s", S ); if (s [0] = 'G') id = 0; else if (s [0] = 'D') id = 1; else if (s [0] = 'M') id = 2; else id = 3; scanf ("% d", & node [I]. c [Id], & node [I]. P [ID]); node [I]. MX = max (node [I]. MX, node [I]. c [ID]); node [I]. flag [ID] = 1 ;}} scanf ("% d", & T); for (I = 0; I <n; I ++) for (j = 0; j <n; j ++) add [I] [J] = 0; while (t --) {scanf ("% d % S % d", &, & B, S, & Val); If (s [0] = 'D') add [hash [a] [hash [B] =-val; else add [hash [a] [hash [B] = val;} scanf ("% d-% d", & A, & B, & C); ansc = ANSP =-INF; DFS (0, 0); If (ansc>-INF) printf ("% d \ n", ansc, ANSP ); else printf ("poor manager! \ N ");}}