which organizes marriages. Marriages is isn't the easy-to-be-made, so, the job was quite hard for you.
The job gets more difficult if people come here and give their bio-data with their preference about opposite gender. Some give priorities to family background, Some give priorities to education, etc.
Now your company are in a danger and you want to save your company from this financial crisis by arranging as much marriage s as possible. So, you collect n bio-data of men and N bio-data of women. After analyzing quite a lot you calculated the ' priority index ' of each pair of men and women.
Finally you want to arrange N marriage ceremonies, such that's total priority index is maximized. Remember that all man should is paired with a woman and only monogamous families should is formed.
Input
Input starts with an integer T (≤100), denoting the number of test cases.
Each case contains a integer N (1≤n≤16), denoting the number of men or women. Each of the next n lines would contain N integers each. The jth integer in the ith line denotes the "priority" index between the ith man and jth Woman. All the integers is positive and not greater than 10000.
Output
For each case, print the case number and the maximum possible, the marriages has been arranged.
Sample Input |
Output for Sample Input |
2 2 1 5 2 1 3 1 2 3 6 5 4 8 1 2 |
Case 1:7 Case 2:1 |
N Men n Women choose N to make their weights the most. It is equivalent to one number per line and these numbers cannot be in the same column.
/************************************************author:guanjuncreated TIME:2016/6/14 19:21:17File Name: 1011.cpp*************************************************/#include<iostream>#include<cstring>#include<cstdlib>#include<stdio.h>#include<algorithm>#include<vector>#include<queue>#include<Set>#include<map>#include<string>#include<math.h>#include<stdlib.h>#include<iomanip>#include<list>#include<deque>#include<stack>#defineull unsigned long Long#definell Long Long#defineMoD 90001#defineINF 0x3f3f3f3f#defineMAXN 10010#defineCLE (a) memset (A,0,sizeof (a))Constull inf = 1LL << A;Const Doubleeps=1e-5;using namespaceStd;priority_queue<int,vector<int>,greater<int> >PQ;structnode{intx, y;};structcmp{BOOL operator() (Node A,node b) {if(a.x==b.x)returnA.y>b.y; returnA.x>b.x; }};BOOLcmpintAintb) { returnA>b;}intdp[1<< -];intn,m;inta[ -][ -];intDfsintSintCNT) { if(s== (1<<n)-1){ returndp[s]=0; } if(dp[s]!=-1)returnDp[s]; for(intI=0; i<n;i++){ if(! (s& (1<<i))) {Dp[s]=max (Dp[s],dfs (s| (1<<i), cnt+1)+A[cnt][i]); } } returndp[s];}intMain () {#ifndef Online_judge freopen ("In.txt","R", stdin); #endif //freopen ("OUT.txt", "w", stdout); intT; CIN>>T; for(intt=1; t<=t;t++) {cin>>N; for(intI=0; i<n;i++) for(intj=0; j<n;j++) scanf ("%d",&A[i][j]); Memset (DP,-1,sizeofDP); printf ("Case %d:%d\n", T,dfs (0,0)); } return 0;}
Lightoj 1011-marriage Ceremonies