F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Yu-Gi-Oh!

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 916    Accepted Submission(s): 283


Problem Description
"Yu-Gi-Oh!", also known as "Dueling Monsters", is a popular trading card game which has nearly 20 years history. Next year, YGO will reach its 20th birthday.

Stilwell has $n$ monsters on the desk, each monster has its $level_i$ and $ATK_i$. There are two kinds of monsters, Tuner monsters and Non-Tuner monsters.

Now, Stilwell plans to finish some "Synchro Summon", and "Synchro Summon" is a kind of special summon following these rules (a little different from the standard YGO rules):

(1) A "Synchro Summon" needs two monsters as the material of this summon, and they must be one Tuner monster and one Non-Tuner monster.
In other words, we can cost one Tuner monster and one Non-Tuner monster to get a Synchro monster ("cost" means remove form the desk, "get" means put on to the desk).

(2) To simplify this problem, Synchro monsters are neither Tuner monsters nor Non-Tuner monsters.

(3) The level sum of two material must be equal to the level of Synchro monster we summon.
For example:
A Level 3 Tuner monster $+$ A Level 2 Non-Tuner monster $=$ A Level 5 Synchro Monster
A Level 2 Tuner monster $+$ A Level 4 Non-Tuner monster $=$ A Level 6 Synchro Monster
A Level 4 Tuner monster $+$ A Level 4 Non-Tuner monster $=$ A Level 8 Synchro Monster

(4) The material of some Synchro monster has some limits, the material must contain some specific monster.
For example:
A Level 5 Synchro Monster $\alpha$ requires A Level 3 Tuner monster $\alpha$ to be its material
A Level 6 Synchro Monster $\beta$ requires A Level 4 Non-Tuner monster $\beta$ to be its material
A Level 8 Synchro Monster $\gamma$ requires A Level 4 Tuner monster $\gamma$ $+$ A Level 4 Non-Tuner monster $\gamma$ to be its material
A Level 5 Synchro Monster $\varphi$ doesn't require any monsters to be its material
Then
A Level 3 Tuner monster $\alpha$ $+$ A Level 2 Non-Tuner monster $=$ A Level 5 Synchro Monster $\alpha$
A Level 3 Tuner monster $\delta$ $+$ A Level 2 Non-Tuner monster $\neq$ A Level 5 Synchro Monster $\alpha$
A Level 2 Tuner monster $+$ A Level 4 Non-Tuner monster $\beta$ $=$ A Level 6 Synchro Monster $\beta$
A Level 3 Tuner monster $+$ A Level 3 Non-Tuner monster $\zeta$ $\neq$ A Level 6 Synchro Monster $\beta$
A Level 4 Tuner monster $\gamma$ $+$ A Level 4 Non-Tuner monster $\gamma$ $=$ A Level 8 Synchro Monster $\gamma$
A Level 4 Tuner monster $\sigma$ $+$ A Level 4 Non-Tuner monster $\gamma$ $\neq$ A Level 8 Synchro Monster $\gamma$
A Level 4 Tuner monster $\gamma$ $+$ A Level 4 Non-Tuner monster $\phi$ $\neq$ A Level 8 Synchro Monster $\gamma$
A Level 3 Tuner monster $+$ A Level 2 Non-Tuner monster $=$ A Level 5 Synchro Monster $\varphi$
A Level 3 Tuner monster $\alpha$ $+$ A Level 2 Non-Tuner monster $=$ A Level 5 Synchro Monster $\varphi$

Stilwell has $m$ kinds of Synchro Monster cards, the quantity of each Synchro Monster cards is infinity.

Now, given $level_i$ and $ATK_i$ of every card on desk and every kind of Synchro Monster cards. Please finish some Synchro Summons (maybe zero) to maximum $\sum ATK_i$ of the cards on desk.
 

Input
The first line of the input contains a single number $T$, the number of test cases.

For each test case, the first line contains two integers $n$, $m$.

Next $n$ lines, each line contains three integers $tuner_i$, $level_i$, and $ATK_i$, describe a monster on the desk. If this monster is a Tuner monster, then $tuner_i=1$, else $tuner_i=0$ for Non-Tuner monster.

Next $m$ lines, each line contains integers $level_j$, $ATK_j$, $r_j$, and following $r_j$ integers are the required material of this Synchro Monster (the integers given are the identifier of the required material).
The input data guarantees that the required material list is available, two Tuner monsters or two Non-Tuner monsters won't be required. If $r_i=2$ the level sum of two required material will be equal to the level of Synchro Monster.

$T\leq 10$, $n,m\leq 300$, $1\leq level_i\leq 12$, $0\leq ATK_i\leq 5000$, $0\leq r_i\leq 2$
 

Output
$T$ lines, find the maximum $\sum ATK_i$ after some Synchro Summons.
 

Sample Input
5 2 2 1 3 1300 0 2 900 5 2300 1 1 8 2500 0 2 1 1 3 1300 1 2 900 5 2300 1 1 3 1 1 3 1300 0 2 900 0 2 800 5 2300 1 1 3 1 1 1 233 0 1 233 0 1 200 2 466 2 1 2 6 3 1 3 1300 0 2 900 0 5 1350 1 4 1800 0 10 4000 0 10 1237 5 2300 1 1 8 3000 0 6 2800 0
 

Sample Output
2300 2200 3200 666 11037
 

Author
SXYZ
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 20:28:27, Gzip enabled