Problem D:headmaster ' s headache
Time Limit:2 seconds
The headmaster of Spring Field School is considering employing some new teachers for certain. There are a number of teachers applying for the posts. Each teacher are able to teach one or more subjects. The headmaster wants to select applicants so this each subject is taught by at least two teachers, and the overall Minimized.
Input
The input consists of several test cases. The format is explained below them:
The contains three positive integers s, M and N. S (≤8) is the number of subjects, M (≤20) is the number of S Erving teachers, and N (≤100) is the number of applicants.
Each of the following M lines describes a serving teacher. It's gives the cost of employing him/her (10000≤c≤50000), followed by a list of subjects that he/she can teach. The subjects are numbered from 1 to S.you must keep in employing all of them. After this there are N lines, giving the details of the applicants in the same format.
The Input is terminated by a null case where S = 0. This case should is processed.
Output
For each test case, the give the minimum cost to employ the teachers under the constraints.
Sample Input
2 2 2
10000 1
20000 2
30000 1 2
40000 1 2
0 0 0
Sample Output
60000