Gold Mine

Time Limit: 2000ms
Memory Limit: 32768KB
This problem will be judged on HDU. Original ID: 3996
64-bit integer IO format: %I64d      Java class name: Main

Description

Long long ago, there is a gold mine.The mine consist of many layout, so some area is easy to dig, but some is very hard to dig.To dig one gold, we should cost some value and then gain some value. There are many area that have gold, because of the layout, if one people want to dig one gold in some layout, he must dig some gold on some layout that above this gold's layout. A gold seeker come here to dig gold.The question is how much value the gold he can dig, suppose he have infinite money in the begin.

Input

First line the case number.(<=10)

Then for every case:
  one line for layout number.(<=100)
  for every layout
  first line gold number(<=25)
  then one line for the dig cost and the gold value(32bit integer), the related gold number that must be digged first(<=50)

then w lines descripte the related gold followed, each line two number, one layout num, one for the order in that layout
see sample for details

Output

Case #x: y.
x for case number, count from 1.
y for the answer.

Sample Input

1
2
1
10 100 0
2
10 100 1
1 1
10 100 1
1 1

Sample Output

Case #1: 270

Source

Language: 
Theme: 
Share Code? 

Powered by NB231 | Current Style: .