#P1559. 运动员最佳匹配问题

运动员最佳匹配问题

Description

A badminton team has nn male athletes and nn female athletes. You are given two n×nn \times n matrices PP and QQ. Pi,jP_{i,j} is the male athlete ii's competitive advantage when paired with female athlete jj in mixed doubles; Qi,jQ_{i,j} is the female athlete ii's competitive advantage when cooperating with male athlete jj.

However, due to various factors such as technical coordination and psychological state, Pi,jP_{i,j} is not necessarily equal to Qj,iQ_{j,i}. The combined competitive advantage of the pair consisting of male athlete ii and female athlete jj is Pi,j×Qj,i\bm{P_{i,j} \times Q_{j,i}}.

Now, design an algorithm to compute the optimal pairing between male and female athletes so that the sum of the combined competitive advantages across all pairs is maximized.

Input Format

The first line contains one positive integer nn (1n20)(1 \le n \le 20). The next 2n2n lines each contain nn numbers. The first nn lines are PP, and the last nn lines are QQ.

Output Format

Output the maximum possible sum of the combined competitive advantages across all pairs.

3
10 2 3
2 3 4
3 4 5
2 2 2
3 5 3
4 5 1
52

Hint

Translated by ChatGPT 5