[题目链接]

https://www.lydsy.com/JudgeOnline/problem.php?id=1433

[算法]

二分图匹配
[代码]

#include<bits/stdc++.h>
using namespace std;
#define MAXN 55 struct edge
{
int to,nxt;
} e[MAXN * MAXN]; int i,j,n,T,tot;
int a[MAXN],b[MAXN],head[MAXN],match[MAXN << ];
bool visited[MAXN << ];
bool g[MAXN][MAXN];
bool ans; template <typename T> inline void read(T &x)
{
int f = ; x = ;
char c = getchar();
for (; !isdigit(c); c = getchar())
{
if (c == '-') f = -f;
}
for (; isdigit(c); c = getchar()) x = (x << ) + (x << ) + c - '';
x *= f;
}
inline void addedge(int u,int v)
{
tot++;
e[tot] = (edge){v,head[u]};
head[u] = tot;
}
inline bool hungary(int u)
{
int i,v;
visited[u] = true;
for (i = head[u]; i; i = e[i].nxt)
{
v = e[i].to;
if (!visited[v])
{
visited[v] = true;
if (!match[v] || hungary(match[v]))
{
match[v] = u;
return true;
}
}
}
return false;
} int main()
{ read(T);
while (T--)
{
read(n);
tot = ;
for (i = ; i <= n; i++)
{
head[i] = ;
match[i] = match[n + i] = ;
}
for (i = ; i <= n; i++) read(a[i]);
for (i = ; i <= n; i++) read(b[i]);
for (i = ; i <= n; i++)
{
for (j = ; j <= n; j++)
{
read(g[i][j]);
}
}
for (i = ; i <= n; i++)
{
if (a[i] == )
{
if (b[i] == ) continue;
for (j = ; j <= n; j++)
{
if ((i == j) || (a[j] == && g[i][j]))
addedge(i,j + n);
}
} else
{
for (j = ; j <= n; j++)
{
if (a[j] == && g[i][j])
addedge(i,j + n);
}
}
}
ans = true;
for (i = ; i <= n; i++)
{
if ((a[i] == && b[i] == ) || a[i] == )
{
memset(visited,false,sizeof(visited));
if (!hungary(i))
{
ans = false;
break;
}
}
}
if (ans) printf("^_^\n");
else printf("T_T\n");
} return ; }

最新文章

  1. css随笔记
  2. 从零开始山寨Caffe&#183;零:必先利其器
  3. Java 集合 - HashSet
  4. Xcode6如何自己添加pch文件?
  5. jenkins配置自动发送邮件
  6. [转]Spring 注解总结
  7. java获取手机号归属地
  8. Linux学习笔记(11)软件包管理
  9. SQL Server 2005导入Excel表问题
  10. 【转】C# 解析 json
  11. LA 2038
  12. mysql教程-触发器
  13. C 循环链表
  14. Html5实现头像上传和编辑,保存为Base64的图片过程
  15. casio 手表北京维修网络
  16. TCP服务端开发为例--web开发不同url请求走不同control方法
  17. php date函数
  18. GO语言初探
  19. 下载android4.4.2源码全过程(附已下载的源码)
  20. spring揭秘 读书笔记 六 bean的一生

热门文章

  1. crontab定时清理日志
  2. TWaver3D特效之高光反射
  3. python_ 学习笔记(运算符)
  4. 39页第7题 计算2的i次方之和
  5. Oracle 常用目录结构(10g)
  6. photon Unity RPC 调用流程
  7. 【Codeforces 1091D】New Year and the Permutation Concatenation
  8. Java基础学习总结(76)——Java异常深入学习研究
  9. -sql语句练习50题(Mysql学习练习版)
  10. MVC和MVVM的区别