HDU 2119 Matrix 简单题

发布时间:2016-12-10 18:55:49 编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"HDU 2119 Matrix 简单题",主要涉及到HDU 2119 Matrix 简单题方面的内容,对于HDU 2119 Matrix 简单题感兴趣的同学可以参考一下。

点击打开链接   Matrix Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1403    Accepted Submission(s): 620 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     Author Wendell     Source HDU 2007-10 Programming Contest_WarmUp     Recommend 威士忌   题意是说给你一个0,1矩阵,让你每次可以将一行或者一列的1变成0,让你求最少几次可以让所有的1都变成0。 二分匹配简单题,将矩阵中是1的格子的x和y坐标记录下来,然后再求最大匹配数即可。 #include<stdio.h> #include<string.h> #define M 107 using namespace std; int vis[M],g[M][M],link[M]; int n,m; bool find(int i) { for(int j=1;j<=m;j++) if(!vis[j]&&g[i][j]) { vis[j]=1; if(link[j]==0||find(link[j])) { link[j]=i; return true; } } return false; } int main() { while(scanf("%d",&n),n) { scanf("%d",&m); int a,count=0; memset(g,0,sizeof(g)); memset(link,0,sizeof(link)); for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) { scanf("%d",&a); if(a==1) g[i][j]=1; } for(int i=1;i<=n;i++) { memset(vis,0,sizeof(vis)); if(find(i)) count++; } printf("%d\n",count); } return 0; }      

下一篇:设备模型、设备与驱动关联的全过程分析 platform_device platform_driver driver bus关系