Athletes the best match problem

Athletes the best match problem 

Time Limit: 1000 ms Memory Limit: 65536 KiB
 

Problem Description

There are various sportsmen and women badminton team n people. Given two n × n matrix P and Q. P [i] [j] is competition advantages male athletes and female athletes Male athletes i j mixed doubles pair consisting of; Q [i] [j] is male athletes and female athletes i j with the advantages of competition female athletes. And due to the psychological state of technology with other factors, P [i] [j] is not necessarily equal to Q [j] [i]. Male athletes and female athletes j i mixed doubles pair consisting of the strengths of both men and women race as P [i] [j] * Q [j] [i].
Design an algorithm to calculate the best male and female athletes paired law so that both men and women in each group reach the maximum sum competition advantage.
Design an algorithm for a given competition advantages male and female athletes, male and female athletes to calculate the best match method, so that both men and women in each group reach the maximum sum competition advantage.

Input

The first line of input data has a positive integer n (1≤n≤20). 2n next row, each row number n. A first n rows of p, the n-th row is q.

Output

The maximum output of the sum of the calculated advantages of both male and female competition.

Sample Input

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

Sample Output

52

Hint

Source

 

. 1 #include <bits / STDC ++ H.>
 2  the using  namespace STD;
 . 3  int n-, Max, sum; // representatives and Max the maximum required, sum temporary sum 
. 4  int Data [ 22 is ] [ 22 is ];
 . 5  int the DATAX [ 22 is ] [ 22 is ], DATAY [ 22 is ] [ 22 is ];
 . 6  int Book [ 22 is ], maxSum [ 22 is ];
 . 7  
. 8  void DFS ( int X) {
 . 9      IF (X> = n-) {max = max (max , SUM); return ;} //After reaching x n, representing the entire marking visited 
10      int CNT = 0 ; // need to write pruning function, or a timeout, prune condition is that (before the sum of x and a good matching after x-> n maxima , add <= Max, subtracted) 
. 11      for ( int I = x; I <n-; I ++) = CNT + maxSum [I]; // after seeking the maximum x boys and girls matching 
12 is      IF (SUM + CNT < max) return ; // if first group x -> sum of n plus the current set of search cnt the matched assuming that the maximum, is still less than max, the pruning can, max is the maximum value has been determined 
13 is      for ( int = I 0 ; I <n-; I ++ ) {
 14          IF ! ( Book [I]) {
 15              Book [I] = . 1 ;
 16              SUM = +data[x][i];
17             dfs(x+1);
18             book[i]=0;//回溯
19             sum-=data[x][i];
20         }
21     }
22 }
23 void input(int data[22][22]){
24     for(int i=0;i<n;i++)
25         for(int j=0;j<n;j++)
26             cin>>data[i][j];
27 }
28 int main()
29 {
30     cin>>n;
31     input(datax);
32     input(datay);
33     Max=0,sum=0;
34     for(int i=0;i<n;i++){
35         for(int j=0;j<n;j++){
36             data[i][j]=datax[i][j]*datay[j][i];
37             maxSum[i]=max(maxSum[i],data[i][j]);
38         }
39         book[i]=0;
40     }
41     dfs(0);
42     cout<<Max<<endl;
43     return 0;
44 }

 

 

Guess you like

Origin www.cnblogs.com/NirobertEinteson/p/11927103.html