Engineer Assignment

Time Limit: 2000/1000 MS (Java/Others)

Memory Limit: 32768/32768 K (Java/Others)

Description

In Google, there are many experts of different areas. For example, MapReduce experts, Bigtable experts, SQL experts, etc. Directors need to properly assign experts to various projects in order to make the projects going smoothly.
There are N projects owned by a director. For the $i^{th}$ project, it needs $C_i$ different areas of experts, $a_{i,0}, a_{i,1}, · · · , a_{i,C_i-1}$ respective. There are M engineers reporting to the director. For the $i^{th}$ engineer, he is an expert of $D_i$ different areas, $b_{i,0}, b_{i,1}, ... , b_{i,D_i-1}.$
Each engineer can only be assigned to one project and the director can assign several engineers to a project. A project can only be finished successfully if the engineers expert areas covers the project areas, which means, for each necessary area of the project, there is at least one engineer
masters it.
The director wants to know how many projects can be successfully finished.

Input

The first line of the input gives the number of test cases, T. T test cases follow. Each test case starts with a line consisting of 2 integers, N the number of projects and M the number of engineers. Then N lines follow. The $i^{th}$ line containing the information of the $i^{th}$ project starts
with an integer $C_i$ then $C_i$ integers follow, $a_{i,0}, a_{i,1}, ... , a_{i,C_i-1}$ representing the expert areas needed for the $i^{th}$ project. Then another M lines follow. The $i_{th}$ line containing the information of the $i^{th}$ engineer starts with an integer $D_i$ then $D_i$ integers follow, $b_{i,0}, b_{i,1}, ... , b_{i,D_i-1}$ representing the expert areas mastered by $i^{th}$ engineer.

Output

For each test case, output one line containing “Case #x: y”, where x is the test case number (starting from 1) and y is the maximum number of projects can be successfully finished.

limits


$\bullet 1 ≤ T ≤ 100.$
$\bullet 1 ≤ N, M ≤ 10.$
$\bullet 1 ≤ C_i ≤ 3.$
$\bullet 1 ≤ D_i ≤ 2.$
$\bullet 1 ≤ a_{i,j} , b_{i,j} ≤ 100.$

Sample Input

1 3 4 3 40 77 64 3 10 40 20 3 40 20 77 2 40 77 2 77 64 2 40 10 2 20 77

Sample Output

Case #1: 2
Hint
For the first test case, there are 3 projects and 4 engineers. One of the optimal solution is to assign the first(40 77) and second engineer(77 64) to project 1, which could cover the necessary areas 40, 77, 64. Assign the third(40 10) and forth(20 77) engineer to project 2, which could cover the necessary areas 10, 40, 20. There are other solutions, but none of them can finish all 3 projects. So the answer is 2.

Hint

jiangzijing2015

Source

2016 CCPC-Final

提交代码