HDU——2119 Matrix
Matrix
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3095 Accepted Submission(s): 1428
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.
题目大意:
给你一个矩阵(只包含0或1),每次你可以选择一行或一列,并删除这一行或这个列中的所有“1”。您的任务是给出删除矩阵中所有“1”的最小时间。
思路:
这个题跟我们前面做的那个碰气球的题一样,是哪个题中的一小部分。
我们要将所有的1都删去,这就跟我们那个题中的我们选定一种颜色,将其全部消灭用的操作数。同样我们每一次只能对一行或者一列进行操作。这样我们对于1的位置的行与列连边,再把这两个(列和边)看作是两个集合。求它的最大匹配数。
一个很简单的二分图的板子。。
代码:

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define N 1500+10
using namespace std;
bool vis[N];
int n,m,k,x,y,girl[N],map[N][N];
int read()
{
int x=0,f=1; char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
int find(int x)
{
for(int i=1;i<=m;i++)
{
if(!vis[i]&&map[x][i])
{
vis[i]=true;
if(girl[i]==-1||find(girl[i])) {girl[i]=x;return 1;}
}
}
return 0;
}
int main()
{
int t=0,sum,ans;
while(1)
{
n=read();if(n==0) break;
m=read(),ans=0;
memset(map,0,sizeof(map));
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
{
x=read();
if(x==1) map[i][j]=1;
}
memset(girl,-1,sizeof(girl));
for(int i=1;i<=n;i++)
{
memset(vis,0,sizeof(vis));
if(find(i)) ans++;
}
printf("%d\n",ans);
}
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 4920 Matrix multiplication(bitset)
HDU 4920 Matrix multiplication 题目链接 题意:给定两个矩阵,求这两个矩阵相乘mod 3 思路:没什么好的想法,就把0的位置不考虑.结果就过了.然后看了官方题解,上面是用 ...
- HDU 2686 Matrix 3376 Matrix Again(费用流)
HDU 2686 Matrix 题目链接 3376 Matrix Again 题目链接 题意:这两题是一样的,仅仅是数据范围不一样,都是一个矩阵,从左上角走到右下角在从右下角走到左上角能得到最大价值 ...
- HDU——T 2119 Matrix
http://acm.hdu.edu.cn/showproblem.php?pid=2119 Time Limit: 5000/1000 MS (Java/Others) Memory Limi ...
- hdu 2119(简单二分图) Matrix
http://acm.hdu.edu.cn/showproblem.php?pid=2119 一个由0和1构成的矩阵,每次选取一行或者一列将其中的1变成0,求最小删除次数 简单的二分图应用,矩阵的横坐 ...
- 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 ...
- HDU 5671 Matrix 水题
Matrix 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5671 Description There is a matrix M that has ...
随机推荐
- SqlServer 2008 创建测试数据
包含要点: 数据库的循环 . insert select 句式 . 随机数(rand()函数).绝对值(abs()函数) ) ) DECLARE @randomvalue float SET @s ...
- asp.net mvc 5 微信接入VB版 - 获取AccessToken
获取AccessToken是微信接入的又一个基础操作.很多微信接口需要这个2小时一刷新的AccessToken作为参数. 转载请说明作者Nukepayload2 首先根据开发文档把获取AccessTo ...
- Java三大特性之封装
.封装 1.概念:把对象的内部细节封闭起来,只提供操作对象属性的公共方法. 封装是面向对象编程语言对客观世界的模拟:如:电视机,她的内部元件就被封闭起来了,仅仅暴露电视机按钮来供人使用,这样就没有人能 ...
- Python3简明教程(九)—— 文件处理
文件是保存在计算机存储设备上的一些信息或数据.你已经知道了一些不同的文件类型,比如你的音乐文件,视频文件,文本文件.Linux 有一个思想是“一切皆文件”,这在实验最后的 lscpu 的实现中得到了体 ...
- hdu6290 奢侈的旅行
最短路算法的复杂度考虑! 书上已经做了优化,用的是优先队列:用优先队列实现堆优化 V为点集,E为边集 从O(V^2)优化到O(ElogV) 然后再记忆一下inf 0x3f3f3f3f的十进制是1061 ...
- win10下安装使用mysql-5.7.23-winx64
下载MySQLhttps://dev.mysql.com/downloads/file/?id=478884 解压到文件,此例为D盘根目录 在mysql-5.7.23-winx64目录下创建[my.i ...
- BI结构图及自动建表结构图
- gocode安装不上的解决办法
mkdir -p $GOPATH/src/golang.org/x //路径下创建此文件 cd $GOPATH/src/golang.org/x //切换到此目录 git clone ht ...
- 去除ie下select框箭头
select::-ms-expand { display: none;}兼容ie10及以上
- STL源码分析与实现-stl_list容器
1. stl_list 介绍 今天我们来总结一下stl_List, 通过之前介绍单链表的文章,其实对链表的基本操作已经十分熟悉了,那对于stl_list,无非就是链表结构不一样,至于其中的增删改查的细 ...