Algorithm title: UVA 10817

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.