BZOJ1059: [ZJOI2007] Matrix game

Source: Internet
Author: User

Description

Little Q is a very clever kid, besides chess, he also likes to play a computer puzzle game-matrix game. The matrix game is carried out in a n*n black-and-white phalanx (as in chess, except that the color is random). You can do two operations on the Matrix at a time: Select any two rows of the matrix, swap the columns of the two lines (that is, the color of the swap grid): Select any column of the matrix, swap the two columns (that is, swap the color of the corresponding lattice) the target of the game, that is, by several operations, the main diagonal The upper-left corner of the line to the lower-right corner of the grid is black. For some of the levels, the small q can not be solved, so that he began to wonder whether these levels are simply no solution!! So little Q decided to write a program to determine whether these levels have a solution.

Input

The first line contains an integer t, which represents the number of groups of data. Next contains the T-group data, each set of data first behaves as an integer n, representing the size of the Phalanx; next n behaves as a n*n 01 matrix (0 for White and 1 for black).

Output

The output file should contain a T line. For each set of data, if the level has a solution, the output line is yes;

Sample Input2
2
0 0
0 1
3
0 0 1
0 1 0
1 0 0Sample OutputNo
Yes
"Data Size"
For 100% of data, n≤200It is not difficult to find that if you can find n points (Xi,yi), so that Xi, Yi or not the same can be done. then obviously a binary graph matching model.
#include <cstdio>#include<cctype>#include<queue>#include<cmath>#include<cstring>#include<algorithm>#defineRep (i,s,t) for (int i=s;i<=t;i++)#defineDwn (i,s,t) for (int i=s;i>=t;i--)#defineren for (int i=first[x];i;i=next[i])using namespacestd;Const intBuffersize=1<< -;Charbuffer[buffersize],*head,*Tail;inlineCharGetchar () {if(head==tail) {        intL=fread (Buffer,1, Buffersize,stdin); Tail= (Head=buffer) +l; }    return*head++;} InlineintRead () {intx=0, f=1;CharC=Getchar ();  for(;! IsDigit (c); C=getchar ())if(c=='-') f=-1;  for(; IsDigit (c); C=getchar ()) x=x*Ten+c-'0'; returnx*F;}Const intmaxn= About;intN,E[MAXN][MAXN],LEFT[MAXN],VIS[MAXN];intMatchintx) {Rep (I,1, N)if(e[x][i]&&!Vis[i]) {Vis[i]=1; if(!left[i]| |match (Left[i])) {Left[i]=x;return 1; }    }    return 0;}intMain () {intt=read ();  while(t--) {memset (left,0,sizeof(left)); Memset (E,0,sizeof(e)); N=read ();intans=0; Rep (I,1, N) Rep (J,1, N) e[i][j]=read (); Rep (I,1, N) {memset (Vis,0,sizeof(VIS)); if(Match (i)) ans++; } puts (ans==n?"Yes":"No"); }    return 0;}
View Code

BZOJ1059: [ZJOI2007] Matrix game

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.