Under construction

Still being built. Things may change

You Shall Pass

Time limit1sMemory limit1024 MB

Summary
Split students into two classes to maximize expected passers, where same-class study groups raise pass probabilities by a_ij, capped at 1.
Level

Medium7 of 10

Topics
Graph
Solved
No attempts yet

문제

Students who fail COT 3100 (Introduction to Discrete Structures) have become a major concern for the UCF professors. Matt and Sean collected a large amount of data and analyzed it, and they produced some probability estimates.

Each student has two base probabilities: the probability of passing Matt's class and the probability of passing Sean's class. Each pair of students ii and jj also has a value aija_{ij}. If students ii and jj are in the same class, they can form a study group, and then student ii's probability of passing increases by aija_{ij}. For example, if student ii's initial probability is 0.4 and aij=0.2a_{ij} = 0.2, then ii's probability of passing with jj in the same class becomes 0.4+0.2=0.60.4 + 0.2 = 0.6.

Matt and Sean want to split the students into two classes so that the expected number of students who pass is as large as possible. Every student is in exactly one class, but one class may be empty.

Given the initial passing probabilities and the increases from study groups, find the maximum expected number of passing students over all ways to split the students into two classes. For any class split, assume that no student's passing probability is ever higher than 1 or lower than 0, even after study group effects are counted.

Input

The first line contains a positive integer gg, the number of semesters to check. The data for each semester starts with an integer nn (2≤n≤502 \le n \le 50), the number of students who signed up for COT 3100 that semester.

The next two lines each contain nn decimal values. The ii-th value of the first line is the probability that student ii passes Matt's class. The ii-th value of the second line is the probability that student ii passes Sean's class.

Then nn lines follow. The ii-th line contains nn non-negative decimal numbers, and the jj-th number on that line is aija_{ij}.

Every decimal value in the input is written with exactly two decimal places, in the form #.##.

Output

For each semester, print the maximum expected number of passing students on its own line. Round the answer to two decimal places (for example, 1.234 rounds to 1.23 and 1.235 rounds to 1.24).

Examples1

  1. Example 1

    Input
    2
    2
    0.75 0.25
    0.25 0.75
    0.00 0.20
    0.20 0.00
    3
    0.20 0.60 0.95
    0.40 0.40 0.95
    0.00 0.00 0.55
    0.00 0.00 0.35
    0.00 0.00 0.00
    
    Expected output
    1.50
    2.65