题目链接: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. 【Python】第一篇:python基础_1

    本篇内容 Python介绍 安装 第一个程序(hello,world) 变量 用户输入(input) 数据类型 数据运算 if判断 break和continue的区别 while 循环 一. Pyth ...

  2. 【Python】Python处理csv文件

    Python处理csv文件 CSV(Comma-Separated Values)即逗号分隔值,可以用Excel打开查看.由于是纯文本,任何编辑器也都可打开.与Excel文件不同,CSV文件中: 值没 ...

  3. Cows and Cars UVA - 10491 (古典概率)

    按照题目的去推就好了 两种情况 1.第一次选择奶牛的门  概率是 a/(a+b) 打开c扇门后  除去选择的门 还剩 a-1-c+b扇门  则选到车的概率为b/(a-1-c+b) 2.第一次选择车的门 ...

  4. 并发时-修改Linux系统下的最大文件描述符限制

    通常我们通过终端连接到linux系统后执行ulimit -n 命令可以看到本次登录的session其文件描述符的限制,如下: $ulimit -n1024 当然可以通过ulimit -SHn 1024 ...

  5. Spring切面二使用注解

    package com.IC; public interface PhoneBiz { public void buyPhone(int num); //购买手机; public void saleP ...

  6. dorado事件

    //----------------------------------------------------------------------------// //校验实体数据是否填写if(enti ...

  7. grafana模板

    1.安静了这么久,换了一家公司,还有过年,去了上海,去了苏州,去了杭州,认识了一个人,跟老司机他们一起学k8s,所以很累很累,这是监控,也是在老司机的帮助下熟悉使用,3q!

  8. Bootsrap 直接使用

    Bootstrap3 直接使用 <!DOCTYPE html> <html> <head> <title>Bootstrap3</title> ...

  9. [DeeplearningAI笔记]序列模型1.5-1.6不同类型的循环神经网络/语言模型与序列生成

    5.1循环序列模型 觉得有用的话,欢迎一起讨论相互学习~Follow Me 1.5不同类型的循环神经网络 上节中介绍的是 具有相同长度输入序列和输出序列的循环神经网络,但是对于很多应用\(T_{x}和 ...

  10. OpenCV---边缘保留滤波EPF

    OpenCV经典的两种实现EPF方法:高斯双边和均值迁移 一:双边模糊 差异越大,越会完整保留 def bi_demo(image): dst = cv.bilateralFilter(image,0 ...