hdu 2119
2015-08-09 20:21
225 查看
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
//最小顶点覆盖=最大匹配
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
//最小顶点覆盖=最大匹配
#include <stdio.h> #include <string.h> int ma[110][110]; int n,m; bool vis[110]; int link[110]; bool Find(int x) { for(int i=0;i<m;i++) { if(!vis[i]&&ma[x][i]) { vis[i]=1; if(link[i]==-1||Find(link[i])) { link[i]=x; return true; } } } return false; } int main() { while(~scanf("%d",&n)&&n) { scanf("%d",&m); memset(link,-1,sizeof(link)); for(int i=0;i<n;i++) for(int k=0;k<m;k++) scanf("%d",&ma[i][k]); int ans=0; for(int i=0;i<n;i++) { memset(vis,0,sizeof(vis)); if(Find(i)) ans++; } printf("%d\n",ans); } return 0; }
相关文章推荐
- MFC之托盘
- [HDU 3923] Invoker polya
- 设计模式--中介者模式
- Android OOM异常解决方案
- 关于进程间互发信息
- 【ME】互联网创业公司失败的7大特征
- QQ连连看辅助c++版本的
- 单例,函数的三种调用方式
- Scut游戏server引擎Unity3d访问
- Android ANR异常解决方案
- 模板方法设计模式
- 代理模式(基础)
- SSH三大框架整合(Hibernate,Spring,struts2)
- Android源代码编译命令m/mm/mmm/make分析
- ModifyMenu的用法
- ubuntu(English)下安装搜狗拼音
- jQuery Mobile 网格
- iOS开发--改变tableHeaderView的高度
- (C/C++学习笔记)多继承的二义性
- 目录手册