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
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.
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.
input, print one line containing the minimum times of deleting all the '1' in
the matrix.
#include <iostream>
#include <cstdio>
#include <cstring> using namespace std; int vis[],Map[][];
int ok[],n,m; bool Find(int x)
{
for (int i=;i<m;i++)
{
if (Map[x][i]==&&!vis[i])
{
vis[i]=;
if (ok[i]==-)
{
ok[i]=x;
return true;
}
else
{
if (Find(ok[i])==true)
{
ok[i]=x;
return true;
}
}
}
}
return false;
} int main()
{
int ans;
while (~scanf("%d",&n))
{
ans=;
if (n==)
break;
scanf("%d",&m);
memset(Map,,sizeof(Map));
memset(ok,-,sizeof(ok));
for (int i=;i<n;i++)
{
for (int j=;j<m;j++)
{
scanf("%d",&Map[i][j]);
}
}
for (int i=;i<n;i++)
{
memset(vis,,sizeof(vis));
if (Find(i))
{
ans++;
}
}
printf ("%d\n",ans);
}
return ;
}
hdu 2119 Matrix(二分匹配)的更多相关文章
- hdu 1281棋盘游戏(二分匹配)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1281 Problem Description 小希和Gardon在玩一个游戏:对一个N*M的棋盘, ...
- HDU 3468 BFS+二分匹配
九野的博客,转载请注明出处 http://blog.csdn.net/acmmmm/article/details/10966383 开始建图打搓了,参考了大牛的题解打的版本比较清爽,后来改的基本雷同 ...
- HDU 2819 Swap (二分匹配+破输出)
题意:给定上一个01矩阵,让你变成一个对角全是 1 的矩阵. 析:二分匹配,把行和列看成两个集合,用匈牙利算法就可以解决,主要是在输出解,在比赛时一紧张不知道怎么输出了. 输出应该是要把 match[ ...
- HDU 2819 — Swap 二分匹配
Swap Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- HDU 2119 Matrix
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2119 解题思路: 处理数据,使用公式最小点覆盖数=最大匹配数,使用匈牙利算法求二分图最大匹配即可. ...
- hdu 1281 棋盘游戏 (二分匹配)
棋盘游戏 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- HDU——2119 Matrix
Matrix Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- Hdu 1498 二分匹配
50 years, 50 colors Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- Fire Net HDU - 1045(二分匹配)
把每一列中相邻的 . 缩为一个点 作为二分图的左边 把每一行中相邻的 . 缩为一个点 作为二分图的右边 然后求最大匹配即可 这题用匈牙利足够了...然而..我用了hk...有点大材小用的感觉// ...
随机推荐
- 【Nginx】转:Nginx try_files
原来的配置是这样的: location / { try_files $uri $uri/ /index.php; index index.html index.htm index.php; } loc ...
- 基于Git制作电子书 GitBook
GitBook 详细介绍 GitBook 是一个基于 Node.js 的命令行工具,可使用 Github/Git 和 Markdown 来制作精美的电子书,GitBook 并非关于 Git 的教程. ...
- 以太网帧,IP,TCP,UDP首部结构
1.以太网帧的格式 以太网封装格式 2.IP报头格式 IP是TCP/IP协议簇中最为重要的协议.所有的TCP,UDP, ICMP和IGMP数据都以IP数据报格式传输.IP提供的是不可靠.无连接的协议. ...
- Fiddler绕过前端直接和后台进行交互
测试需求:有一个功能,允许用钻石兑换金币,假设1钻石=1金币,前端控制一次至少兑换10个,最多100个,后台不做验证. 测试方案:输入10,也就是告诉前端我要兑换10个金币,等前端验证通过之后,截取要 ...
- 最大流Dinic算法模板(pascal)
program rrr(input,output); const inf=; type pointer=^nodetype; nodetype=record t,c:longint; next,rev ...
- python写BMI指数菜单
需求: # 1.创建并输出菜单, 菜单是不可变的. 所以使用元组menus = ("1, 录入", "2, 查询", "3, 删除", &q ...
- VS中碰到的问题
1.调试的时候,语句已经注释掉了,但是在执行的时候还是运行了(或者某些变量值改变后,程序依然用的之前数据). 右键解决方案-->清理,然后重新生成.
- 题解 P1628 【合并序列】
看到这个题,小金羊第一秒的反应就是: 优先队列可解! 看到楼上某同学一个个比较, find()函数是时候现身了! string//类型库 //find具体用法可以自行百度 //这里仅说这里的用法(逃) ...
- 洛谷 P3258 [JLOI2014]松鼠的新家
树剖,裸题,鉴定完毕. 我是题面 读完题,恩,树剖,裸题,没劲. 处理很简单,既然每到一个房间吃一块糖,那么就在每条路径上的每个房间放一颗糖,但是每条路径的终点也就是下一条路径的起点,在这里只能加一次 ...
- 高rong效chang的可持久化treap
很多人觉得可持久化treap很慢,但是事实上只是他们可持久化treap的写法不对.他们一般是用split和merge实现所有功能,但是这样会有许多不必要的分裂.其实我们可以用一种特殊的方式来实现插入和 ...