题目链接: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

Problem Description
Give you a matrix(only contains 0 or 1),every time you
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.

 
Input
There are several test cases.

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.

 
Output
For each of the test cases, in the order given in the
input, print one line containing the minimum times of deleting all the '1' in
the matrix.
 
Sample Input
3 3
0 0 0
1 0 1
0 1 0
0
 
Sample Output
2
 
Author
Wendell
 
 
Source
 
题目大意:将矩阵所给的1全部变成0,每次改变可以变换一行或者一列。问最少多少次,可以使矩阵里的所有元素全部变为0?
解题思路:将横坐标X看做二分图的左支,纵坐标Y看做二分图的右支。求二分图的最小点覆盖=二分图的最匹配数。
 
详见代码。
 #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(二分匹配)的更多相关文章

  1. hdu 1281棋盘游戏(二分匹配)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1281   Problem Description 小希和Gardon在玩一个游戏:对一个N*M的棋盘, ...

  2. HDU 3468 BFS+二分匹配

    九野的博客,转载请注明出处 http://blog.csdn.net/acmmmm/article/details/10966383 开始建图打搓了,参考了大牛的题解打的版本比较清爽,后来改的基本雷同 ...

  3. HDU 2819 Swap (二分匹配+破输出)

    题意:给定上一个01矩阵,让你变成一个对角全是 1 的矩阵. 析:二分匹配,把行和列看成两个集合,用匈牙利算法就可以解决,主要是在输出解,在比赛时一紧张不知道怎么输出了. 输出应该是要把 match[ ...

  4. HDU 2819 — Swap 二分匹配

    Swap Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  5. HDU 2119 Matrix

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2119 解题思路: 处理数据,使用公式最小点覆盖数=最大匹配数,使用匈牙利算法求二分图最大匹配即可. ...

  6. hdu 1281 棋盘游戏 (二分匹配)

    棋盘游戏 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  7. HDU——2119 Matrix

    Matrix Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  8. Hdu 1498 二分匹配

    50 years, 50 colors Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  9. Fire Net HDU - 1045(二分匹配)

    把每一列中相邻的 .  缩为一个点 作为二分图的左边 把每一行中相邻的  .  缩为一个点 作为二分图的右边 然后求最大匹配即可 这题用匈牙利足够了...然而..我用了hk...有点大材小用的感觉// ...

随机推荐

  1. [转帖]IBM收购Red Hat

    来源cnbeta:https://www.cnbeta.com/articles/tech/782009.htm 2018年10月28 日,IBM 宣布收购 Linux 巨头 Red Hat.公告中称 ...

  2. web_config配置

    <configuration>    <system.web>      <compilation debug="true" targetFramew ...

  3. 利用css3的text-shadow属性实现文字阴影乳白效果

    现在CSS3+html5的网页应用的越来越广泛了.很多网页中的字体同样可以用CSS3来实现炫酷的效果. 下面就介绍一下利用css3的text-shadow属性实现文字阴影乳白效果.这是在设计达人上面看 ...

  4. 洛谷 P1560 蜗牛的旅行

    明显这是一道搜索题,其他题解写的有点复杂,我有更简便的写法 既然题目说走到不能再走,那我们就干脆一点,一条路走到黑,不到南墙不回头,一下把要走的路都走完,不但效率高,也好写,关键是大大节省了系统栈 一 ...

  5. StringUtils工具类说明

    /***************************************为空判断***************************************/ //null 和 " ...

  6. ms17-010漏洞扫描工具

    说明: 1.先利用masscan进行445端口探测 2.利用巡风的脚本对开放445端口的IP进行ms17-010漏洞扫描. 3.使用方法:Python2运行后,按提示输入单个IP或者IP网段. # c ...

  7. POJ.1426 Find The Multiple (BFS)

    POJ.1426 Find The Multiple (BFS) 题意分析 给出一个数字n,求出一个由01组成的十进制数,并且是n的倍数. 思路就是从1开始,枚举下一位,因为下一位只能是0或1,故这个 ...

  8. 特征点检测学习_2(surf算法)

    依旧转载自作者:tornadomeet 出处:http://www.cnblogs.com/tornadomeet 特征点检测学习_2(surf算法) 在上篇博客特征点检测学习_1(sift算法) 中 ...

  9. Selective Search for Object Recognition

    http://blog.csdn.net/charwing/article/details/27180421 Selective Search for Object Recognition 是J.R. ...

  10. Codeforces 526.D Om Nom and Necklace

    D. Om Nom and Necklace time limit per test 1 second memory limit per test 256 megabytes input standa ...