Transmission Door
FFF
time limit (normal/java):
ms/
MS
Run memory limit: 65536 KByte
Total Submissions: 145 test pass:
Title Description
FFF Regiment, a heretic trial organization, members active in all corners, whenever the barbecue festival comes, we can hear the familiar melody they spread:
Burning Ah ~ burning Ah ~ burning ah burning ~ (please do your own brain repair "when")
FFF members of the group with such a property: Out of nowhere to change the torch and gasoline, the two together to let the fire of FFF Duang burn up, but different torches and different gasoline to produce the flame is different, there are now n kinds of torches and n kind of gasoline, The intensity of the flame that is known to match each torch with each gasoline now asks how to pair the torch with petrol one by one to produce the most exuberant flame.
Input
The first behavior is an integer t, which indicates that there is a T group of data
First behavior of each group of data a positive integer n (2≤n≤30)
The second line begins with a total of n rows, each n positive integer, and the number of J of line I indicates the intensity of the flame of the first I torch in conjunction with the J Petrol. (0<a[i][j]≤10000)
Output
Each set of data outputs an integer representing the maximum flame intensity
Sample input
2
3
5 2 6
6 7 9
7 4 1
4
8 5 2 8
5 8 2 1
9 6 3 7
7 5 8 1
Sample output
20
33
Source of the topic
Kojimai
The Wdd of the turn:
http://blog.csdn.net/u010535824/article/details/44746223
A: Two-to-one pairing, both solutions, a binary maximum weights to match the KM algorithm can be solved, the second is the maximum cost of the flow, the two are directly set the template of the algorithm can be.
Here's how the KM is done
njczy2010 |
2073 |
Accepted |
0MS |
212K |
2522Byte |
g++ |
2015-04-01 17:14:34.0 |
1#include <cstdio>2#include <cstring>3#include <stack>4#include <vector>5#include <algorithm>6#include <map>7#include <string>8#include <queue>9#include <cmath>Ten One #definell Long Long A int ConstN = *; - int ConstM =100005; - int ConstINF =0x3f3f3f3f; thellConstMoD =1000000007; - - using namespacestd; - + intT; - intN; + intNx,ny;//points on both sides A intG[n][n];//two-part diagram description at intLinker[n],lx[n],ly[n];//Point Matching status in Y, Dot label in X, y - intSlack[n]; - BOOLVisx[n],visy[n]; - - BOOLDFS (intx) - { inVISX[X] =true; - for(inty =0; y < ny;y++) to { + if(Visy[y])Continue; - intTMP = Lx[x] + ly[y]-G[x][y]; the if(TMP = =0) * { $Visy[y] =true;Panax Notoginseng if(Linker[y] = =-1||DFS (Linker[y])) - { theLinker[y] =x; + return true; A } the } + Else if(Slack[y] >tmp) -Slack[y] =tmp; $ } $ return false; - } - the intKM () - {Wuyimemset (linker,-1,sizeof(linker)); thememset (Ly,0,sizeof(ly)); - for(inti =0; I < nx;i++) Wu { -Lx[i] =-INF; About for(intj =0; J < ny;j++) $ if(G[i][j] >Lx[i]) -Lx[i] =G[i][j]; - } - for(intx =0; x < nx;x++) A { + for(inti =0; i < NY; i++) theSlack[i] =INF; - while(true) $ { thememset (VISX,false,sizeof(VISX)); thememset (Visy,false,sizeof(Visy)); the if(DFS (x)) Break; the intD =INF; - for(inti =0; I < ny;i++) in if(!visy[i] && d >Slack[i]) theD =Slack[i]; the for(inti =0; I < NX; i++) About if(Visx[i]) theLx[i]-=D; the for(inti =0; i < NY; i++) the { + if(Visy[i]) ly[i] + =D; - ElseSlack[i]-=D; the }Bayi } the } the intres =0; - for(inti =0; i < NY; i++) - if(Linker[i]! =-1) theRes + =g[Linker[i]][i]; the returnRes; the } the - voidINI () the { thescanf"%d",&n); the inti,j;94 for(i =0; I < n;i++){ the for(j =0; J < n;j++) thescanf"%d",&g[i][j]); the }98NX = NY =N; About } - 101 voidSolve ()102 {103 104 } the 106 void out()107 {108printf"%d\n", KM ());109 } the 111 intMain () the {113 //freopen ("data.in", "R", stdin); the //freopen ("Data.out", "w", stdout); thescanf"%d",&T); the //for (int cnt=1;cnt<=t;cnt++)117 while(t--)118 //while (scanf ("%d%d%d", &a,&b,&n)!=eof)119 { - ini ();121 solve ();122 out();123 }124}
"Asian Credit Technology Cup" South Mail seventh session of college students Program Design Competition Network preliminary noj 2073 FFF [binary graph maximum weight matching | | Maximum cost maximum flow]