BZOJ 1059 [ZJOI2007]矩阵游戏 (二分图最大匹配)
1059: [ZJOI2007]矩阵游戏
Time Limit: 10 Sec Memory Limit: 162 MB
Submit: 5281 Solved: 2530
[Submit][Status][Discuss]
Description
Input
Output
输出文件应包含T行。对于每一组数据,如果该关卡有解,输出一行Yes;否则输出一行No。
Sample Input
2
0 0
0 1
3
0 0 1
0 1 0
1 0 0
Sample Output
Yes
【数据规模】
对于100%的数据,N ≤ 200
HINT
Source
析:对于同行或者是同列的数,那么无论经过多少次变化,那么肯定也是同行同列,那么也就是求能不能找到 n 个不同不同列的1。也就是二分图的最大匹配。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#include <list>
#include <assert.h>
#include <bitset>
#include <numeric>
#define debug() puts("++++")
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define fi first
#define se second
#define pb push_back
#define sqr(x) ((x)*(x))
#define ms(a,b) memset(a, b, sizeof a)
#define sz size()
#define pu push_up
#define pd push_down
#define cl clear()
//#define all 1,n,1
#define FOR(i,x,n) for(int i = (x); i < (n); ++i)
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1e17;
const double inf = 1e20;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 400 + 10;
const int maxm = 3e5 + 10;
const ULL mod = 3;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, -1, 0, 1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c) {
return r >= 0 && r < n && c >= 0 && c < m;
} struct Edge{
int to, next;
};
Edge edges[maxn*maxn<<1];
int head[maxn], cnt; void addEdge(int u, int v){
edges[cnt].to = v;
edges[cnt].next = head[u];
head[u] = cnt++;
} int match[maxn];
bool vis[maxn]; bool dfs(int u){
vis[u] = 1;
for(int i = head[u]; ~i; i = edges[i].next){
int v = edges[i].to, w = match[v];
if(w < 0 || !vis[w] && dfs(w)){
match[u] = v;
match[v] = u;
return true;
}
}
return false;
} int main(){
int T; cin >> T;
while(T--){
scanf("%d", &n);
ms(head, -1); cnt = 0;
for(int i = 0; i < n; ++i)
for(int j = 0; j < n; ++j){
int x; scanf("%d", &x);
if(x) addEdge(i, j+n), addEdge(j+n, i);
}
int ans = 0; ms(match, -1);
for(int i = 0; i < n; ++i) if(match[i] < 0){
ms(vis, 0); if(dfs(i)) ++ans;
}
puts(ans == n ? "Yes" : "No");
}
return 0;
}
BZOJ 1059 [ZJOI2007]矩阵游戏 (二分图最大匹配)的更多相关文章
- bzoj 1059: [ZJOI2007]矩阵游戏 二分图匹配
1059: [ZJOI2007]矩阵游戏 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1891 Solved: 919[Submit][Statu ...
- bzoj 1059: [ZJOI2007]矩阵游戏 [二分图][二分图最大匹配]
Description 小Q是一个非常聪明的孩子,除了国际象棋,他还很喜欢玩一个电脑益智游戏——矩阵游戏.矩阵游戏在一个N *N黑白方阵进行(如同国际象棋一般,只是颜色是随意的).每次可以对该矩阵进行 ...
- BZOJ 1059: [ZJOI2007]矩阵游戏( 匈牙利 )
只要存在N个x, y坐标均不相同的黑格, 那么就一定有解. 二分图匹配, 假如最大匹配=N就是有解的, 否则无解 ------------------------------------------- ...
- BZOJ 1059 [ZJOI2007]矩阵游戏
1059: [ZJOI2007]矩阵游戏 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2707 Solved: 1322[Submit][Stat ...
- bzoj 1059 [ZJOI2007]矩阵游戏(完美匹配)
1059: [ZJOI2007]矩阵游戏 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2993 Solved: 1451[Submit][Stat ...
- BZOJ 1059: [ZJOI2007]矩阵游戏 匈牙利算法
1059: [ZJOI2007]矩阵游戏 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2351 Solved: 1156 题目连接 http:// ...
- 【bzoj1059】[ZJOI2007]矩阵游戏 二分图最大匹配
题目描述 小Q是一个非常聪明的孩子,除了国际象棋,他还很喜欢玩一个电脑益智游戏——矩阵游戏.矩阵游戏在一个N*N黑白方阵进行(如同国际象棋一般,只是颜色是随意的).每次可以对该矩阵进行两种操作:行交换 ...
- BZOJ 1059 [ZJOI2007]矩阵游戏:二分图匹配
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1059 题意: 给你一个n*n的01矩阵. 你可以任意次地交换某两行或某两列. 问你是否可以 ...
- 1059: [ZJOI2007]矩阵游戏 二分图匹配
https://www.lydsy.com/JudgeOnline/problem.php?id=1059 裸的二分图匹配,行列匹配即可 /****************************** ...
随机推荐
- go语言path包和filepath包的学习与使用
path包的使用 package main; import ( "fmt" "path" ) //go语言path包的学习 func main() { //返回 ...
- datepicker动态初始化
datepicker 初始化动态表单的input,需要调用jquery的on方法来给未来元素初始化. //对动态添加的时间文本框进行动态初始化 $('table').on("focus&qu ...
- Git两分钟指南-学习入门参考
Git两分钟指南 http://blog.jobbole.com/78999/ GIT和SVN之间的五个基本区别 http://www.oschina.net/news/12542/git-and-s ...
- Java并发-懒汉式单例设计模式加volatile的原因
懒汉式单例的double check.例一: class SingletonClass{ private static SingletonClass instance = null; private ...
- opencv 双边模糊,膨胀腐蚀 开 闭操作
#include <opencv2/opencv.hpp> #include <iostream> using namespace cv; int main(int argc, ...
- nginx默认配置和默认站点启动
1.nginx的配置文件nginx.conf cd /etc/nginx/ vim nginx.conf 打开后的文件为: user nginx;worker_processes 1; error_l ...
- HTML&&css练习
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- hdu 1983(BFS+DFS) 怪盗Kid
http://acm.hdu.edu.cn/showproblem.php?pid=1983 首先,题目要求出口和入口不能封闭,那么,只要把出口或入口的周围全给封闭了那盗贼肯定无法成功偷盗,出口或入口 ...
- http协议(一)一些基础知识
当我们在浏览器的地址栏中输入网址,然后点击回车,接着,浏览器就会呈现出我们需要的web界面,那么,这个界面是怎么产生的? web的界面是根据我们输入的URL(网址.地址),浏览器从服务器端获取对应的文 ...
- codeforces round#510
蒟蒻和以前一样还是只能做 $4$ 题, 希望有一天可以 水到 $5$ 题!! 不过也终于上了蓝了... A. Benches Description 给出$N$个座位, 每个座位上初始有$a_i$ ...