1059: [ZJOI2007] Matrix game

Source: Internet
Author: User

1059: [ZJOI2007] Matrix gameDescriptionLittle Q is a very clever kid, besides chess, he also likes to play a computer puzzle game-matrix game. Matrix game in an n*n Black-and-white phalanx (as in chess, only colors are casual). You can do two operations on the Matrix at a time: The row Exchange operation: Selectany two lines of the matrix, exchanging these two lines (that is, the color of the swap corresponding lattice) The column Exchange operation: Select any row of the matrix and swap the two columns (that is, the Exchangecorresponding to the color of the lattice) the goal of the game, that is, through a number of operations, so that the main diagonal of the matrix (the upper left to the lower right corner of the connection) on the grid is blackcolor. 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 processto determine if there are any solutions to these levels. InputThe first line contains an integer t, which represents the number of groups of data. Next contains the T-group data, the first behavior of each group of data an integer n, representing the large squareSmall; next n behaves as a n*n 01 matrix (0 for White, 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 01 0 0 Sample Output No
Yes
"Data Size"
for 100% of data, n≤200 The following:binary graph maximum matching: the problem is very ingenious, because no matter how the exchange of rows, the consent line or the number in the same column will not change, but the position has changed. so the question turns into asking if there are 1 different rows of N.
#include <stdio.h>#include<iostream>#include<algorithm>#include<string.h>using namespacestd;intt,i,j,n,ans,a[205][205],f[205],p[205];inttot,head[205],next[40005],to[40005];voidAddintXinty) {Tot++; To[tot]=y; Next[tot]=Head[x]; HEAD[X]=tot;}intDfsintXintT) {    inti;  for(i=head[x];i!=-1; i=Next[i])if(p[to[i]]!=T) {inty=To[i]; P[y]=u; if(f[y]==0||DFS (F[Y],T)) {F[y]=x; return 1; }    }    return 0;}intMain () {scanf ("%d",&T);  while(t--) {scanf ("%d",&N); Tot=0;  for(i=1; i<=n;i++) {Head[i]=-1; F[i]=p[i]=0; }         for(i=1; i<=n;i++)          for(j=1; j<=n;j++) {scanf ("%d",&A[i][j]); if(A[i][j]) Add (I,J); } ans=0;  for(i=1; i<=n;i++) {ans+=DFS (i,i); }        if(ans==n) printf ("yes\n");Elseprintf"no\n"); }    return 0;}

1059: [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.