HDU-2119-Matrix(最大匹配)
链接:https://vjudge.net/problem/HDU-2119#author=Smilencer
题意:
众所周知,tyz是一个写bug小能手,以至于如果没有队友的帮助,就ac不了程序。
今天可怜的XJL又被抓来出数据debug了,你要帮助他以最少的样例消灭所有程序的bug
数据以矩阵的形式表示出来,整个矩阵中只包含0,1两个数。其中1代表一个bug。
已知每出一个样例可以消灭一行或者一列的bug,即把一行或一列所有的1变成0。
你的任务是求出最少需要找多少个样例才能使得整个程序没有bug,即矩阵中的1全部被清除
思路:
x,y建立二分图。
代码:
#include <iostream>
#include <memory.h>
#include <string>
#include <istream>
#include <sstream>
#include <vector>
#include <stack>
#include <algorithm>
#include <map>
#include <queue>
#include <math.h>
#include <cstdio>
#include <set>
#include <iterator>
#include <cstring>
using namespace std; typedef long long LL;
const int MAXN = 5e3+10;
int Next[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; vector<int> G[MAXN];
int Map[110][110];
int Link[MAXN], Vis[MAXN];
int n, m, k; bool Dfs(int x)
{
for (int node = 1;node <= m;node++)
{
if (Map[x][node] && Vis[node] == 0)
{
Vis[node] = 1;
if (Link[node] == -1 || Dfs(Link[node]))
{
Link[node] = x;
return true;
}
}
}
return false;
} int Solve()
{
memset(Link, -1, sizeof(Link));
int cnt = 0;
for (int i = 1;i <= n;i++)
{
memset(Vis, 0, sizeof(Vis));
if (Dfs(i))
cnt++;
}
return cnt;
} int main()
{
while (~scanf("%d", &n) && n)
{
scanf("%d", &m);
for (int i = 1;i <= n;i++)
for (int j = 1;j <= m;j++)
scanf("%d", &Map[i][j]);
int cnt = Solve();
printf("%d\n", cnt);
} return 0;
}
HDU-2119-Matrix(最大匹配)的更多相关文章
- hdu 2119 Matrix(二分匹配)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2119 Matrix Time Limit: 5000/1000 MS (Java/Others) ...
- HDU 2119 Matrix
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2119 解题思路: 处理数据,使用公式最小点覆盖数=最大匹配数,使用匈牙利算法求二分图最大匹配即可. ...
- HDU——2119 Matrix
Matrix Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- HDU 4920 Matrix multiplication(bitset)
HDU 4920 Matrix multiplication 题目链接 题意:给定两个矩阵,求这两个矩阵相乘mod 3 思路:没什么好的想法,就把0的位置不考虑.结果就过了.然后看了官方题解,上面是用 ...
- HDU 2686 Matrix 3376 Matrix Again(费用流)
HDU 2686 Matrix 题目链接 3376 Matrix Again 题目链接 题意:这两题是一样的,仅仅是数据范围不一样,都是一个矩阵,从左上角走到右下角在从右下角走到左上角能得到最大价值 ...
- hdu 2119(简单二分图) Matrix
http://acm.hdu.edu.cn/showproblem.php?pid=2119 一个由0和1构成的矩阵,每次选取一行或者一列将其中的1变成0,求最小删除次数 简单的二分图应用,矩阵的横坐 ...
- HDU——T 2119 Matrix
http://acm.hdu.edu.cn/showproblem.php?pid=2119 Time Limit: 5000/1000 MS (Java/Others) Memory Limi ...
- HDU 2853 (KM最大匹配)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2853 题目大意:二分图匹配费用流.①最大匹配②最小原配变动 解题思路: 如果去掉第二个要求,那么就是裸 ...
- hdu 2686 Matrix 最小费用最大流
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2686 Yifenfei very like play a number game in the n*n ...
- hdu 5569 matrix dp
matrix Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5569 D ...
随机推荐
- html5+css3酷炫音频播放器代码
1. [代码][JavaScript]代码 (function($){ jQuery.fn.extend({ "initAudio" : fun ...
- 使用同一个目的port的p2p协议传输的tcp流特征相似度计算
结论: (1)使用同一个目的port的p2p协议传输的tcp流特征相似度高达99%.如果他们是cc通信,那么应该都算在一起,反之就都不是cc通信流. (2)使用不同目的端口的p2p协议传输的tcp流相 ...
- codeforces 705C C. Thor(模拟)
题目链接: C. Thor time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- Seq2SQL :使用强化学习通过自然语言生成SQL
论文: https://einstein.ai/static/images/layouts/research/seq2sql/seq2sql.pdf 数据集:https://github.com/s ...
- nginx rewrite 导致验证码不正确
配置nginx里url rewrite的时候,为了使浏览器地址栏的URL保持不变, 使用proxy_pass反向代理,但发现每次都会生成新的jsessionid 解决方法,配置中增加 proxy_co ...
- 损失函数(Loss function) 和 代价函数(Cost function)
1损失函数和代价函数的区别: 损失函数(Loss function):指单个训练样本进行预测的结果与实际结果的误差. 代价函数(Cost function):整个训练集,所有样本误差总和(所有损失函数 ...
- BZOJ_1025_[SCOI2009]游戏_DP+置换+数学
BZOJ_1025_[SCOI2009]游戏_DP+置换 Description windy学会了一种游戏.对于1到N这N个数字,都有唯一且不同的1到N的数字与之对应.最开始windy把数字按 顺序1 ...
- 百度地图API的第一次接触——标注和信息窗的使用
1.定义js函数,用于在指定位置添加标注,在标注位置添加并打开信息窗口 function addMarker(point, index){ // 创建图标对象 var myIcon = new BMa ...
- "The object cannot be deleted because it was not found in the ObjectStateManager."
最近优化EF的性能时遇到一个问题, 当在EF生成的Entityes的构造里加上: this.protocolnodes.MergeOption = MergeOption.NoTracking;thi ...
- Python创建删除文件
Python代码如下: import os directory = "E:\\学习日志\\" os.chdir(directory) # 改变当前工作目录 cwd = os.get ...