hdu 2119 Matrix(二分匹配)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2119
Matrix
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2205 Accepted Submission(s):
975
can select a row or a column and delete all the '1' in this row or this column
.
Your task is to give out the minimum times of deleting all the '1' in
the matrix.
The first line
contains two integers n,m(1<=n,m<=100), n is the number of rows of the
given matrix and m is the number of columns of the given matrix.
The next n
lines describe the matrix:each line contains m integer, which may be either ‘1’
or ‘0’.
n=0 indicate the end of input.
input, print one line containing the minimum times of deleting all the '1' in
the matrix.
#include <iostream>
#include <cstdio>
#include <cstring> using namespace std; int vis[],Map[][];
int ok[],n,m; bool Find(int x)
{
for (int i=;i<m;i++)
{
if (Map[x][i]==&&!vis[i])
{
vis[i]=;
if (ok[i]==-)
{
ok[i]=x;
return true;
}
else
{
if (Find(ok[i])==true)
{
ok[i]=x;
return true;
}
}
}
}
return false;
} int main()
{
int ans;
while (~scanf("%d",&n))
{
ans=;
if (n==)
break;
scanf("%d",&m);
memset(Map,,sizeof(Map));
memset(ok,-,sizeof(ok));
for (int i=;i<n;i++)
{
for (int j=;j<m;j++)
{
scanf("%d",&Map[i][j]);
}
}
for (int i=;i<n;i++)
{
memset(vis,,sizeof(vis));
if (Find(i))
{
ans++;
}
}
printf ("%d\n",ans);
}
return ;
}
hdu 2119 Matrix(二分匹配)的更多相关文章
- hdu 1281棋盘游戏(二分匹配)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1281 Problem Description 小希和Gardon在玩一个游戏:对一个N*M的棋盘, ...
- HDU 3468 BFS+二分匹配
九野的博客,转载请注明出处 http://blog.csdn.net/acmmmm/article/details/10966383 开始建图打搓了,参考了大牛的题解打的版本比较清爽,后来改的基本雷同 ...
- HDU 2819 Swap (二分匹配+破输出)
题意:给定上一个01矩阵,让你变成一个对角全是 1 的矩阵. 析:二分匹配,把行和列看成两个集合,用匈牙利算法就可以解决,主要是在输出解,在比赛时一紧张不知道怎么输出了. 输出应该是要把 match[ ...
- HDU 2819 — Swap 二分匹配
Swap Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- HDU 2119 Matrix
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2119 解题思路: 处理数据,使用公式最小点覆盖数=最大匹配数,使用匈牙利算法求二分图最大匹配即可. ...
- hdu 1281 棋盘游戏 (二分匹配)
棋盘游戏 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- HDU——2119 Matrix
Matrix Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- Hdu 1498 二分匹配
50 years, 50 colors Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- Fire Net HDU - 1045(二分匹配)
把每一列中相邻的 . 缩为一个点 作为二分图的左边 把每一行中相邻的 . 缩为一个点 作为二分图的右边 然后求最大匹配即可 这题用匈牙利足够了...然而..我用了hk...有点大材小用的感觉// ...
随机推荐
- mysql项目路径URL编码
jdbc_url=jdbc:mysql://127.0.0.1:3306/test?serverTimezone=UTC&useUnicode=true&characterEncodi ...
- Debugger DataSet 调试时查看DataSet
delphi 跟踪调试的时候查看DataSet数据记录 Ctrl+F7调试 增强工具DataSethttp://edn.embarcadero.com/article/40268 http://do ...
- jmeter 配置元件之计数器Counter
用jmeter生成数据 我用过几种以下几种方法 1.CSV Data Set Config 参数化 2.${_Random} ${_Random}是jmeter函数助手里面自带的一个函数,作用是返回 ...
- 【移动端debug-3】部分安卓机型不触发touchend事件的解决方案
最近在项目中遇到一个奇怪的问题,有一个需求是这样:页面上有一个按钮,滚动页面时让它消失,停止滚动时让它显示. 常规思路: step1.监听touchstart事件,记录Touch对象中pageY初始值 ...
- 【uoj#225】[UR #15]奥林匹克五子棋 构造
题目描述 两个人在 $n\times m$ 的棋盘上下 $k$ 子棋,问:是否存在一种平局的情况?如果存在则输出一种可能的最终情况. 输入 第一行三个正整数 $n,m,k$ ,意义如前所述. 输出 如 ...
- 【Mybatis】<foreach>标签在mybatis中的使用
mapper.xml如下: <select id="selectCkspcb" parameterType="java.util.Map" resultT ...
- Contest 9
A:搜索好难啊根本不会啊. B:暴力枚举给哪段前缀乘,维护一些前后缀最大最小值之类的东西就很好算了. #include<iostream> #include<cstdio> # ...
- HttpHelper类及调用
首先列出HttpHelper类 /// <summary> /// Http操作类 /// </summary> public class HttpHelper { priva ...
- castle activerecord 学习过程出现的问题
优点: 1.CRUD:代码简洁 2.不用配置map 3.自带事务方便 4.自带IOC 5.自带 数据有效性验证 缺点: 1.自增长(Oracle 一直提示序号不存在,有空继续尝试) 2.多条件,直接用 ...
- [SDOI2011]黑白棋 kth - nim游戏
题面 题面 题解 观察题目,我们可以发现,这个游戏其实就是不断再把对方挤到一边去,也就是黑子不断往左走,白子不断往右走. 因此可以发现,如果将黑白子按顺序两两配对,那么它们中间的距离会不断缩小,且每次 ...