Description xiaoq is a very intelligent child. In addition to chess, he also enjoys playing a computer puzzle game, matrix game. Matrix games are played in an N * n black/white matrix (just like playing chess, the color is random ). You can perform two operations on the matrix each time: Row exchange operation: select any two rows of the matrix and exchange the two rows (that is, swap the color of the corresponding grid) column exchange operation: select any row and column of the Matrix, and exchange the two columns (that is, swap the color of the corresponding grid) to the game's target, that is, through several operations, the main diagonal line of the matrix (the line from the upper left to the lower right corner) the grid on is black. Q cannot solve certain levels, so that he began to doubt whether these levels are completely unsolvable !! So Xiao Q decided to writeProgramTo determine whether these levels are resolved. The first line of input contains an integer T, indicating the number of data groups. Next, the data contains t groups. The first behavior of each group is an integer N, indicating the size of the square matrix. The next n behavior is an 01 matrix of N * n (0 indicates white, and 1 indicates black ). The output file should contain t rows. For each group of data, if the level is resolved, a row of yes is output; otherwise, a row of no is output. Sample input220 00 130 0 10 1 01 0 0 sample outputnoyes [data scale] for 20% of data, n ≤ 7 for 50% of data, n ≤ 50 for 100% of data, n ≤ 200
Very standard Binary Graph Matching. You can directly create rows and columns.
Accode:
# Include <cstdio> # include <cstdlib> # include <string> # include <cstring> const int maxn = 210; bool MP [maxn] [maxn], marked [maxn]; int link [maxn], n; inline int getint () {int res = 0; char TMP; while (! Isdigit (TMP = getchar (); Do res = (RES <3) + (RES <1) + TMP-'0 '; while (isdigit (TMP = getchar (); Return res;} bool find (int I) {for (Int J = 0; j <n; ++ J) if (MP [I] [J] &! Marked [J]) {marked [J] = 1; if (link [J] =-1 | find (link [J]) {link [J] = I; return 1 ;}} return 0 ;}int main () {freopen ("matrix. in "," r ", stdin); freopen (" matrix. out "," W ", stdout); For (int t = getint (); t; -- t) {n = getint (); For (INT I = 0; I <n; ++ I) for (Int J = 0; j <n; ++ J) MP [I] [J] = getint (); for (INT I = 0; I <n; ++ I) link [I] =-1; int ans = 0; For (INT I = 0; I <N; ++ I) {memset (MA Rked, 0, sizeof marked); ans + = find (I);} printf ("% s \ n", ANS> = n? "Yes": "no");} return 0 ;}