hdu2119(二分图+最小点覆盖+匈牙利算法)
来源:互联网 发布:rpc调用 vscode 插件 编辑:程序博客网 时间:2024/06/05 10:52
Matrix
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1312 Accepted Submission(s): 574
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.
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.
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 01 0 10 1 00
Sample Output
2本题的意思是给你一个矩阵,一次操作只能将一行或一列的1全变为0,问最少需要几次能够将矩阵中的1全变为0若将1的行号作为二分图的一部分顶点,1的列号作为二分图的另一部分顶点,然后连一条边,就构成一个二分图,题目即求二分图的最小点覆盖,有理论:一个二分图中的最大匹配数等于这个图中的最小点覆盖数,及转化为求二分图的最大匹配数,运用匈牙利算法可以快速求得#include<iostream>#include<cstdio>#include<map>using namespace std;const int MAX=110;int M[MAX][MAX];//二分图匹配(匈牙利算法的DFS实现)//初始化:g[][]两边顶点的划分情况//建立g[i][j]表示i->j的有向边就可以了,是左边向右边的匹配//g没有边相连则初始化为0//uN是匹配左边的顶点数,vN是匹配右边的顶点数//调用:res=hungary();输出最大匹配数//优点:适用于稠密图,DFS找增广路,实现简洁易于理解//时间复杂度:O(VE)//****************************************************************//顶点编号从0开始的const int MAXN=510;int uN,vN;//u,v数目int g[MAXN][MAXN];int linker[MAXN];bool visited[MAXN];bool dfs(int u)//从左边开始找增广路径{ int v; for(v=0;v<vN;v++)//这个顶点编号从0开始,若要从1开始需要修改 if(g[u][v]&&!visited[v]) { visited[v]=true; if(linker[v]==-1||dfs(linker[v])) {//找增广路,反向 linker[v]=u; return true; } } return false;//这个不要忘了,经常忘记这句}int hungary(){ int res=0; int u; memset(linker,-1,sizeof(linker)); for(u=0;u<uN;u++) { memset(visited,0,sizeof(visited)); if(dfs(u)) res++; } return res;}//****************************************************int main(){int i,j;while(~scanf("%d",&uN),uN){scanf("%d",&vN);memset(g,0,sizeof(g));for(i=0;i<uN;i++){for(j=0;j<vN;j++){ scanf("%d",&M[i][j]);if(M[i][j])g[i][j]=1;}}printf("%d\n",hungary());}return 0;}
- hdu2119(二分图+最小点覆盖+匈牙利算法)
- hdu1054(二分图+最小点覆盖数+匈牙利算法)
- 【POJ 3041 】Asteroids (匈牙利算法最小点覆盖&二分图)
- POJ3041 二分图最小点覆盖(匈牙利算法)
- poj3041 Asteroids 最小点覆盖 二分图 匈牙利算法BFS
- 最小点集覆盖/HDU2119
- HDU2119 Matrix 【最小点覆盖】
- uva11419 【最大二分匹配求最小点覆盖 匈牙利算法】
- POJ 1325 Machine Schedule (二分图最小点集覆盖 匈牙利算法)
- POJ 1422 Air Raid (二分图最小点集覆盖 匈牙利算法)
- POJ-1947-Asteroids-求最小点覆盖数(二分图-匈牙利算法)
- POJ-1325-Machine Schedule-最小点覆盖(二分图-匈牙利算法)
- UVALive 6811 Irrigation Lines (二分图最小点覆盖--匈牙利算法)
- poj 3020 Antenna Placement (最小路径覆盖, 匈牙利算法, 拆点形成二分图)
- poj3041_匈牙利算法_二分图最小覆盖点(最大匹配数)
- POJ 1463 Strategic game (二分图最小覆盖点(匈牙利算法) 或 树形DP)
- scu4439 Vertex Cover(二分图最小点覆盖 匈牙利)
- hdu2119—Matrix(最小点覆盖)
- 学习arm裸机程序
- android颜色配置表--表二
- Makefile 中:= ?= += =的区别
- 读书笔记1——《HTTP权威指南》
- 比较具有从google earth下载影像并拼接功能的两个软件getscreen VS sggs
- hdu2119(二分图+最小点覆盖+匈牙利算法)
- 将tomcat安装为服务
- iOS应用开发最佳实践
- 获取图片名称以及图片路径
- (转载)图的割点、桥与双连通分支
- 不同服务器数据库之间的数据操作
- SPOJ HAN01(典型汉诺塔)
- java BingInteger生成2进制String循环移位时长度自动缩减
- sql 百万级数据库优化方案