Campaign Stops

Time limit1sMemory limit128 MB

Summary
Pick campaign stops and a round tour from city 1 that sways the most voters within the available hours.
Level

Medium7 of 10

Topics
Dynamic programming, Graph
Solved
No attempts yet

Problem

One important part of running an election-year campaign is to visit many places, give your carefully crafted stump speech, and convince as many potential voters as possible to vote for you. Unfortunately, there are only so many hours in a day, so you cannot go everywhere. You therefore have to plan your campaign trips carefully, trading off travel time, the time spent at each stop, and the number of voters you can sway. It is best to let a computer do the planning for you.

For each candidate campaign stop you are given the number of voters you expect to sway by appearing there and the number of hours you would have to spend at that location. In addition, for each ordered pair of stops you are given the travel time from one to the other. Given the total number of hours available, you can then plan an itinerary that sways as many voters as possible.

The tour always starts at city 1 and must return to city 1, but you do not have to campaign there — you may pass through it without spending its hours. Likewise, you may pass through any other city without campaigning; in that case you spend none of its hours and gain none of its voters.

Input

The first line contains a number K≥1K \ge 1, the number of data sets in the file. It is followed by KK data sets of the following form.

The first line of each data set contains two numbers nn and HH. Here 1≤n≤101 \le n \le 10 is the number of candidate campaign stops, and 1.0≤H≤24.01.0 \le H \le 24.0 is the number of hours you have available (this may be fractional).

This is followed by nn lines, each describing one campaign stop with two numbers: an integer vi≥0v_i \ge 0 and a fractional number hi≥0h_i \ge 0. viv_i is the number of voters you could sway at that stop, and hih_i is the number of hours you would have to spend there.

Finally, this is followed by nn more lines, each containing nn numbers, where the jj-th number of line ii is the fractional travel time from city ii to city jj. Thus the ii-th number of line ii is 00, but the travel time from city ii to city jj is not necessarily equal to the travel time from city jj to city ii.

Output

For each data set, first output “Data Set x:” on a line by itself, where xx is its number. Then output the maximum number of voters that can be swayed within the available time HH. The tour always starts at city 1 and has to return there, although the candidate does not have to campaign there.

Examples1

  1. Example 1

    Input
    1
    4 13.5
    100 3.5
    100 1.0
    300 2.0
    140 5.0
    0.0 1.0 4.0 1.5
    1.0 0.0 5.0 0.5
    5.0 5.0 0.0 5.5
    2.0 0.7 6.0 0.0
    
    Expected output
    Data Set 1:
    400