传送门

每一行的1和每一列的1不管怎么换还是在同一行和同一列

目标状态中有n个1是不同行且不同列的

那么就是能否找出n个不同行不同列的1

就是每一行选一个不同列的1

如果矩阵中位置i,j为1,那么点i到点j连一条边

跑匈牙利即可

#include <cstdio>
#include <cstring>
#include <iostream>
#define N 201 using namespace std; int T, n, cnt;
int head[N], to[N * N], nex[N * N], belong[N];
bool vis[N]; inline int read()
{
int x = 0, f = 1;
char ch = getchar();
for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
for(; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch - '0';
return x * f;
} inline bool dfs(int u)
{
int i, v;
for(i = head[u]; ~i; i = nex[i])
{
v = to[i];
if(!vis[v])
{
vis[v] = 1;
if(!belong[v] || dfs(belong[v]))
{
belong[v] = u;
return 1;
}
}
}
return 0;
} inline bool solve()
{
int i, ans = 0;
for(i = 1; i <= n; i++)
{
memset(vis, 0, sizeof(vis));
ans += dfs(i);
}
return ans == n;
} inline void add(int x, int y)
{
to[cnt] = y;
nex[cnt] = head[x];
head[x] = cnt++;
} int main()
{
int i, j, x;
T = read();
while(T--)
{
cnt = 0;
memset(head, -1, sizeof(head));
memset(belong, 0, sizeof(belong));
n = read();
for(i = 1; i <= n; i++)
for(j = 1; j <= n; j++)
{
x = read();
if(x) add(i, j);
}
if(solve()) puts("Yes");
else puts("No");
}
return 0;
}

  

最新文章

  1. Python中下划线的使用方法
  2. JS的基础语法
  3. 1.4.2 solr字段类型--(1.4.2.5)使用枚举字段
  4. Android(java)学习笔记106-1:深入分析Java ClassLoader原理
  5. statspack系列2
  6. 字符串的使用(string,StringBuffer,StringBuilder)
  7. H5页面适配所有iPhone和安卓机型的六个技巧
  8. java 文件字节输出流
  9. 使用git部署服务器
  10. window.onload 和 $(document).ready(function(){})的区别
  11. MyCat 枚举分片设计思考,查询命中条件
  12. 【TensorFlow篇】--反向传播
  13. Python人工智能学习笔记
  14. nginx启用status状态页
  15. border三角形
  16. Liunx/RHEL6.5 Oracle11 安装记录[缺少依赖包的解决方案]
  17. Spring Boot + Spring Cloud 构建微服务系统(十):配置中心(Spring Cloud Bus)
  18. python get请求
  19. ElasticSearch客户端注解使用介绍
  20. sql优化常用命令总结

热门文章

  1. UVA 11988 Broken Keyboard (链表)
  2. SC || Chapter 3
  3. Logistic回归,梯度上升算法理论详解和实现
  4. MarkdownPad 2 Pro 注册码
  5. 2_分布式计算框架MapReduce
  6. day2-python 登录
  7. json_encode() 避免转换中文
  8. 记一次header跨域与cookie共享
  9. python之自定义排序函数sorted()
  10. solr配置中文分词器