编程介的小学生 2017-02-23 08:46 采纳率: 0.2%
浏览 830
已采纳

Curriculum Made Easy

WishingBone has many courses at school. Usually he has to make out his own schedule. Some of the courses are easies than the others, and more often than not, mastery of a pre-requisite course helps the study of a subsequent course. For instance, Numerical Analysis takes Linear Algebra as a pre-requisite course so that it takes 50 hours to master NA with LA knowledge, which would otherwise take 100 hours. WishingBone learns at an average rate of 5 hours everyday, and is free to study his courses in any sequential order. Mathematically speaking, when WishingBone learns courses in the order c1, c2, c3, ..., cn, the time for course ci is the minimal time for learning ci without any pre-requisite or with pre-requisite cj where j < i. Notice that mastery of two pre-requisites does not make double effects. He wants to know what the minimal time he can finish a bunch of courses could be.

Input

The first line of input is a positive integer N <= 10, which is the number of test cases.

The first line of each case contains an integers n (0 < n <= 100), which is the total number of courses he has at school.

Descriptions of the n courses follow. First line of each description is in the form name time p, which are the name of the course (up to 30 upper and lower characters and the '_' character, with no other characters embedded), the time to learn this course without any pre-requisites, and the number of lines below.

Each p lines below are in the form name time which lists a possible pre-requisite and the substitute time.

After the descriptions is a line with a single integer m (0 <= m <= n), which is the number of courses WishingBone has already mastered. The next line lists the m names of the courses.

Output

For each test case output the minimal number of days WishingBone can finish the rest of his courses.

Sample Input

2
3
Economics 50 0
Linear_Algebra 50 0
Numerical_Analysis 100 2
Economics 1000
Linear_Algebra 50
2
Economics Linear_Algebra
3
Data_Structure 100 0
Algorithm_Design 80 1
Data_Structure 72
ACMICPC 60 2
Data_Structure 53
Algorithm_Design 47
0

Sample Output

10
44

  • 写回答

2条回答 默认 最新

  • threenewbee 2017-03-01 22:24
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?