| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 680 人关注过本帖
标题:Troubles of the engineer
只看楼主 加入收藏
心剑菩提
Rank: 1
等 级:新手上路
帖 子:249
专家分:0
注 册:2007-5-17
收藏
 问题点数:0 回复次数:3 
Troubles of the engineer
Description

X is a famous engineer. He has to finish n (1<=n<17) project, but he does not have enough time. Thus he decides to employ some workers to do these projects. Now there are m (1<=m<=100) people applying for the job, and each of them can finish some projects alone. However, the engineer has to pay to them. X wants to pay least money to hire some employees to do these n projects. So how can he choose?

Input

Every group of test data starts with two rows, first row includes a number n and the next one includes a number m. And then there are n rows, each row includes a character string that is less than 30 and composed by lowercases, and the string means the name of the project. Finally, there are m rows, each row has two positive integers which is a and b (a means the payment for this employee, and b means he or she can finish b projects alone), following with these two integers there are b names of the projects he or she can finish.

Output

For each group of test data, we print out a positive integer means the least payment X needs to pay for the n projects. If X cannot finish these n projects, print out -1.

Sample Input


5 5
a
b
c
d
e
1000 5 a b c d e
10 2 a b
100 3 c d e
111 3 a c e
50 4 a c d e
5 4
a
b
c
d
e
100 1 a
100 2 a b
100 3 a b c
100 4 a b c d


Sample Output


60
-1


Source
搜索更多相关主题的帖子: engineer Troubles 
2008-08-16 10:47
心剑菩提
Rank: 1
等 级:新手上路
帖 子:249
专家分:0
注 册:2007-5-17
收藏
得分:0 
怎么每人看啊?

前世五百次的回眸 才换来今生的擦肩而过
2008-08-20 08:09
lingluoz
Rank: 2
来 自:苏州科技学院
等 级:新手上路
威 望:4
帖 子:749
专家分:0
注 册:2008-2-2
收藏
得分:0 
我看的 可以e文的看不懂

Murphy's Law :
If there are two or more ways to do something, and one of those ways can result in a catastrophe, then someone will do it.
2008-08-20 11:10
lingluoz
Rank: 2
来 自:苏州科技学院
等 级:新手上路
威 望:4
帖 子:749
专家分:0
注 册:2008-2-2
收藏
得分:0 
可以->可是

Murphy's Law :
If there are two or more ways to do something, and one of those ways can result in a catastrophe, then someone will do it.
2008-08-20 11:11
快速回复:Troubles of the engineer
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015079 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved