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 ...
随机推荐
- 洛谷 P1726 上白泽慧音
题目描述 在幻想乡,上白泽慧音是以知识渊博闻名的老师.春雪异变导致人间之里的很多道路都被大雪堵塞,使有的学生不能顺利地到达慧音所在的村庄.因此慧音决定换一个能够聚集最多人数的村庄作为新的教学地点.人间 ...
- Android(java)学习笔记171:服务(service)之绑定服务调用服务里面的方法
1.绑定服务调用服务里面的方法,图解: 步骤: (1)在Activity代码里面绑定 bindService(),以bind的方式开启服务 : bindServ ...
- Recyclerview设置间距
首先自定义一个RecyclerViewDivider 继承 RecyclerView.ItemDecoration,实现自定义. public class RecyclerViewDivider ex ...
- idea创建和部署tomcat项目
小编今天花费了一上午,参悟出了如何快速的在idea上面创建并部署一个属于自己的maven项目,很荣幸能将自己的开发经验推而广之,希望能够帮助到大家! 前言 小编参考博文: Intellij Idea ...
- k8s 重要概念[转]
在实践之前,必须先学习 Kubernetes 的几个重要概念,它们是组成 Kubernetes 集群的基石. Cluster Cluster 是计算.存储和网络资源的集合,Kubernetes 利用这 ...
- github下拉刷新与上拉加载地址
https://github.com/chrisbanes/Android-PullToRefresh
- PHP fpm配置和优化
pm.max_children = 1024 #最大子进程数 maximum number of child processes when pm is set to 'dynamic' or 'ond ...
- 转载:CentOS7下部署Django项目详细操作步骤
部署是基于:centos7+nginx+uwsgi+python3+django 之上做的 文章转自:Django中文网 https://www.django.cn/article/sh ...
- activemq常用配置
所用版本为apache-activemq-5.15.4的版本 修改端口号 当端口号冲突时,可以修改这两个端口号.修改activemq.xml 修改里面的61616端口.修改jetty.xml,修改里面 ...
- Java学习之流Stream理解(一)
缓存可以说是I/O的一种性能优化.缓存流为I/O流增加了内存缓冲区.有了缓冲区,使得在流上执行skip().mark()和reset()方法都称为可能. 1.BufferedInputStream 类 ...