HDU——T 2119 Matrix

http://acm.hdu.edu.cn/showproblem.php?pid=2119

Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3097    Accepted Submission(s): 1429

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

威士忌   |   We have carefully selected several similar problems for you:  2115 2117 2114 2118 2120

格点为一的格子坐标连边

 1 #include <cstring>
 2 #include <cstdio>
 3
 4 bool vis[110];
 5 int map[110][110];
 6 int n,m,match[110];
 7
 8 bool find(int x)
 9 {
10     for(int y=1;y<=m;y++)
11         if(map[x][y]&&!vis[y])
12         {
13             vis[y]=1;
14             if(!match[y]||find(match[y]))
15             {
16                 match[y]=x;
17                 return true;
18             }
19         }
20     return false;
21 }
22
23 int main()
24 {
25     for(;scanf("%d",&n)&&n;)
26     {
27         int ans=0;
28         scanf("%d",&m);
29         for(int i=1;i<=n;i++)
30             for(int j=1;j<=m;j++)
31             scanf("%d",&map[i][j]);
32         for(int i=1;i<=n;i++)
33           {
34               if(find(i)) ans++;
35               memset(vis,0,sizeof(vis));
36           }
37         printf("%d\n",ans);
38         memset(map,0,sizeof(map));
39         memset(match,0,sizeof(match));
40     }
41     return 0;
42 }
时间: 2024-10-26 23:47:25

HDU——T 2119 Matrix的相关文章

HDU 2119 Matrix 简单二分匹配

行做x集,列做y集,1就给该行该列连一条边,输出最大匹配边即可 #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<vector> #include<set> using namespace std; #define N 105 int lef[N], pn;//lef[v]表示Y集的点v 当前连接的点 , pn为x点集的

hdu 2119 Matrix(二分匹配)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2119 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

HDU 4965 Fast Matrix Calculation 【矩阵】

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4965 题目大意:给你一个N*K的矩阵A以及一个K*N的矩阵B (4 <= N <= 1000)以及 (2 <=K <= 6),然后接下来四步: 算一个新的矩阵C=A*B 算M=C^ (N*N) 对于M中的每个元素%6 将M中每个元素加起来,算出和. 也就是求出A*B * A*B * A*B * A*B * A*B *--* A*B   但是A*B形成的矩阵是N*N,而N大小有可能是10

hdu 4965 Fast Matrix Calculation(矩阵快速幂)

题目链接:hdu 4965 Fast Matrix Calculation 题目大意:给定两个矩阵A,B,分别为N*K和K*N: 矩阵C = A*B 矩阵M=CN?N 将矩阵M中的所有元素取模6,得到新矩阵M' 计算矩阵M'中所有元素的和 解题思路:因为矩阵C为N*N的矩阵,N最大为1000,就算用快速幂也超时,但是因为C = A*B, 所以CN?N=ABAB-AB=AC′N?N?1B,C' = B*A, 为K*K的矩阵,K最大为6,完全可以接受. #include <cstdio> #inc

HDU 4965 Fast Matrix Calculation(矩阵快速幂)

HDU 4965 Fast Matrix Calculation 题目链接 矩阵相乘为AxBxAxB...乘nn次,可以变成Ax(BxAxBxA...)xB,中间乘n n - 1次,这样中间的矩阵一个只有6x6,就可以用矩阵快速幂搞了 代码: #include <cstdio> #include <cstring> const int N = 1005; const int M = 10; int n, m; int A[N][M], B[M][N], C[M][M], CC[N]

矩阵乘法 --- hdu 4920 : Matrix multiplication

Matrix multiplication Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 820    Accepted Submission(s): 328 Problem Description Given two matrices A and B of size n×n, find the product of them. b

HDU 4965 Fast Matrix Calculation(矩阵高速幂)

HDU 4965 Fast Matrix Calculation 题目链接 矩阵相乘为AxBxAxB...乘nn次.能够变成Ax(BxAxBxA...)xB,中间乘n n - 1次,这样中间的矩阵一个仅仅有6x6.就能够用矩阵高速幂搞了 代码: #include <cstdio> #include <cstring> const int N = 1005; const int M = 10; int n, m; int A[N][M], B[M][N], C[M][M], CC[N

HDU 5015 233 Matrix(西安网络赛I题)

HDU 5015 233 Matrix 题目链接 思路:矩阵快速幂,观察没一列,第一个和为左边加最上面,第二个可以拆为左边2个加最上面,第三个可以拆为为左边3个加最上面,这样其实只要把每一列和每一列右边那列的233构造出一个矩阵,进行矩阵快速幂即可 代码: #include <cstdio> #include <cstring> typedef long long ll; const int N = 15; const int MOD = 10000007; int n, m; s

hdu 4965 Fast Matrix Calculation(矩阵快速幂)2014多校训练第9场

Fast Matrix Calculation                                                                   Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Problem Description One day, Alice and Bob felt bored again, Bob knows Ali