Matrix 二分图
来源:互联网 发布:中国体制 知乎 编辑:程序博客网 时间:2024/06/17 02:57
Matrix
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2234 Accepted Submission(s): 992
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
题解:给你一个N*M的0/1矩阵,你每次可以选特定的某行或某列,然后删除该行/列的所有1,问你最少需要几次操作能删除矩阵的所有1.
最小点覆盖 = 最大匹配
#include<stdio.h>#include<string.h>#include<iostream>using namespace std;int n,m,ans=0;int link[101];int visit[101];int map[101][101];int dfs(int i){int j;for(j=1;j<=m;j++){if(map[i][j]==1 && visit[j]==0){visit[j]=1;if(link[j]==0 || dfs(link[j]==1)){ link[j]=1;//找到,加1 return 1;}}}return 0;}int main(){int x,y,i,j;scanf("%d%d",&n,&m);memset(map,0,sizeof(map));memset(link,0,sizeof(link));for(i=1;i<=n;i++){for(j=1;j<=m;j++){scanf("%d",&map[i][j]);}}for(i=1;i<=n;i++){//从每个顶点出发,依次遍历 memset(visit,0,sizeof(visit));if(dfs(i)==1){//看是否能找到新的一对 ans++;}}printf("%d",ans);}
阅读全文
1 0
- (二分图匹配) Matrix
- Matrix 二分图
- 二分图匹配:Matrix Transformer
- hdu 2119 Matrix-二分图
- hdu_2119 Matrix 二分图匹配
- hdu Matrix 2119 二分图匹配
- [ZOJ 3646]Matrix Transformer[二分图匹配]
- poj3685 Matrix 二分答案
- 二分-poj-3685-Matrix
- POJ3685 Matrix 二分搜索
- POJ - 3685 Matrix 二分
- 二分匹配 HDU2119 Matrix
- POJ 3685:Matrix 二分
- POJ - 3685 Matrix(二分)
- poj3685 Matrix二分
- hdu Matrix(二分图的最小路径覆盖)
- HDU 2119 Matrix【二分图之最小点集覆盖】
- Matrix Transformer zoj3646 (二分图最大匹配)
- 【android学习】android知识点总结
- 计算机常识--数据
- 03-JDBC连接MySQL数据库【插入数据】
- 海康sdk库调用NET_DVR_CaptureJPEGPicture 函数出现107错误
- git撤销add 和 commit
- Matrix 二分图
- ADO.NET与外部数据库连接及查询等基本操作
- 《提问的智慧》摘要
- BZOJ3224+洛谷3369普通平衡树 splay版
- 如何在Python程序中使用二维数组
- CF
- Oracle RAC数据库维护
- python~crush之analyze工具
- windows下Python2与Python3共存的使用方法以及pip的使用方法以及pip安装报错:is not a supported wheel on this platform的处理方法