Test instructions: n * N 01 Matrix, can do two operations: ① two lines exchange; ② two columns. Ask if you can go through several operations, so that the matrix from the top left to the bottom right diagonal is all 1. The problem: The first line Exchange, the column exchange when the relative position of the element will not change, the matrix is equal to the existence of n horizontal axis, the ordinate is not the same point. The Hungarian algorithm, the core algorithm. CODE:
/*Author:JDDPROG:bzoj1059 Matrix Game date:2015.9.24*/#include<cstdio>#include<cstring>#defineREP (i, S, N) for (int i = s; i <= n; i + +)#defineRep_ (i, S, N) for (int i = n; i >= s; i-)#defineMax_n 205using namespacestd;intN;BOOLMap[max_n][max_n], used[max_n];intL[max_n];voidinit () {scanf ("%d", &N); memset (Map,0,sizeof(map)); REP (i,1, N) REP (J,1, N) { intX scanf"%d", &x); if(x) Map[i][j] =1; } memset (L,0,sizeof(L));}BOOLFindintx) {REP (i,1, N) { if(Map[x][i] &&!Used[i]) {Used[i]=1; if(L[i] = =0||find (L[i])) {L[i]=x; return 1; } } } return 0;}voiddoit () {REP (I,1, N) {memset (used,0,sizeof(used)); if(!find (i)) {printf ("no\n"); return; }} printf ("yes\n");}intMain () {intT scanf"%d", &T); while(T--) {init (); Doit (); } return 0;}
bzoj1059 ZJOI2007 Matrix Game