bzoj1059: [ZJOI2007] Matrix game

Source: Internet
Author: User
Tags cas

The maximum match of the binary graph. to a 01 matrix, you can move the column and ask if you can make the top left to bottom right diagonal all 1. The line is the point, run directly can. forgot to return false; WA had it once

#include <cstdio> #include <cstring> #include <iostream> #include <algorithm>using namespace STD; #define REP (I,s,t) for (int. i=s;i<=t;i++) #define CLR (x,c) memset (x,c,sizeof (x)) #define QWQ (x) for (Edge *o=head[x ];o;o=o->next) int read () {int X=0;char C=getchar (), while (!isdigit (c)) C=getchar (), while (IsDigit (c)) x=x*10+c-' 0 ', C=getchar (); return x;} const int nmax=205;struct edge{int To;edge *next;}; Edge Edges[nmax*nmax],*pt,*head[nmax<<1];bool vis[nmax<<1];int match[nmax<<1];void Add (int s,int t ) {pt->to=t;pt->next=head[s];head[s]=pt++;} bool Dfs (int x) {QWQ (x) {int to=o->to;if (vis[to]) continue;vis[to]=true;if (match[to]==-1| | DFS (Match[to])) {Match[to]=x;return true;}} return false;} bool Solve (int n) {int Ans=0;rep (i,1,n) {clr (vis,0); if (Dfs (i)) Ans++;else break;} return ans==n;} void Init () {clr (head,0);p t=edges;clr (match,-1);} int main () {int cas=read (); Rep (I,1,cas) {init (); int N=read (); Rep (J,1,n) Rep (k,1,n) {int tmp=read (); if (tmp==1) Add (j,n+k );} if (Solve (n)) printf ("yes\n"), Else printf ("no\n");} return 0;}

  

1059: [ZJOI2007] Matrix game time limit:10 Sec Memory limit:162 MB
submit:3732 solved:1799
[Submit] [Status] [Discuss] Description Small 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. The first line of Input 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≤200HINT Source [Submit] [Status] [Discuss]

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.