#P3705. [SDOI2017] 新生舞会

    ID: 1335 远端评测题 1500ms 250MiB 尝试: 1 已通过: 0 难度: 8 上传者: 标签>2017二分各省省选山东O2优化最大流分数规划费用流

[SDOI2017] 新生舞会

Description

The school is holding a freshmen welcome ball. As an experienced senior, Cathy is responsible for pairing up dance partners.

There are nn boys and nn girls at the ball. Each pair consists of one boy and one girl, forming a one-to-one matching.

Cathy collected relationship information between these students, such as whether two people knew each other before, and computed ai,ja_{i,j}.

Cathy also needs to consider how convenient it is for two people to dance together, for example whether their height and weight differences are too large, and computed bi,jb_{i,j}, which represents the incompatibility when the ii-th boy dances with the jj-th girl.

Of course, there are many other issues to consider.

Cathy wants to first use a program to find a plan based on ai,ja_{i,j} and bi,jb_{i,j}, and then manually fine-tune the result.

A plan consists of nn pairs of partners. Suppose the joy levels of the pairs are a1,a2,...,ana'_1, a'_2, ..., a'_n, and the incompatibility levels are b1,b2,...,bnb'_1, b'_2, ..., b'_n. Let C=a1+a2+...+anb1+b2+...+bnC=\frac {a'_1+a'_2+...+a'_n}{b'_1+b'_2+...+b'_n}. Cathy wants to maximize the value of CC.

Input Format

The first line contains an integer nn.

The next nn lines each contain nn integers. In the ii-th line, the jj-th number denotes ai,ja_{i,j}.

The next nn lines each contain nn integers. In the ii-th line, the jj-th number denotes bi,jb_{i,j}.

Output Format

Output a single number, the maximum value of CC. Round to 66 decimal places. Your output must exactly match the standard output.

3
19 17 16
25 24 23
35 36 31
9 5 6
3 4 2
7 8 9
5.357143

Hint

Constraints:

  • For 10%10\% of the testdata, 1n51 \le n \le 5.
  • For 40%40\% of the testdata, 1n181 \le n \le 18.
  • Additionally, for 20%20\% of the testdata, bi,j=1b_{i,j} = 1.
  • For 100%100\% of the testdata, 1n100,1ai,j,bi,j1041 \le n \le 100, 1 \le a_{i,j}, b_{i,j} \le 10^4.

Translated by ChatGPT 5