Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 12565   Accepted: 4651

Description

Rain has pummeled the cows' field, a rectangular grid of R rows and C columns (1 <= R <= 50, 1 <= C <= 50). While good for the grass, the rain makes some patches of bare earth quite muddy. The cows, being meticulous grazers, don't want to get their hooves dirty while they eat.

To prevent those muddy hooves, Farmer John will place a number of wooden boards over the muddy parts of the cows' field. Each of the boards is 1 unit wide, and can be any length long. Each board must be aligned parallel to one of the sides of the field.

Farmer John wishes to minimize the number of boards needed to cover the muddy spots, some of which might require more than one board to cover. The boards may not cover any grass and deprive the cows of grazing area but they can overlap each other.

Compute the minimum number of boards FJ requires to cover all the mud in the field.

Input

* Line 1: Two space-separated integers: R and C

* Lines 2..R+1: Each line contains a string of C characters, with '*' representing a muddy patch, and '.' representing a grassy patch. No spaces are present.

Output

* Line 1: A single integer representing the number of boards FJ needs.

Sample Input

4 4
*.*.
.***
***.
..*.

Sample Output

4

Hint

OUTPUT DETAILS:

Boards 1, 2, 3 and 4 are placed as follows: 
1.2. 
.333 
444. 
..2. 
Board 2 overlaps boards 3 and 4.

 
 
 
 
 
 
代码:
 //F - Muddy Fields POJ - 2226
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn=;
const int N=maxn*maxn/;
int G[N][N],vis[N],link[N];
int n;
bool Find(int u){
for(int i=;i<=n;i++){
if(G[u][i]&&!vis[i]){
vis[i]=;
if(link[i]==-||Find(link[i])){
link[i]=u;
return true;
}
}
}
return false;
}
int solve(){
int cnt=;
memset(link,-,sizeof(link));
for(int i=;i<=n;i++){
memset(vis,,sizeof(vis));
if(Find(i))cnt++;
}
return cnt;
}
char mat[maxn][maxn];
int vis1[maxn][maxn],vis2[maxn][maxn];
int main(){
int m;
for(int i=;i<=;i++)
mat[][i]=mat[i][]='.';
while(~scanf("%d%d",&n,&m)){
for(int i=;i<=n;i++){
for(int j=;j<=m;j++)
cin>>mat[i][j];
}
int tot1=,tot2=;
memset(vis1,,sizeof(vis1));
memset(vis2,,sizeof(vis2));
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
if(mat[i][j]=='*'){
if(!vis1[i][j-])vis1[i][j]=tot1++;
else vis1[i][j]=vis1[i][j-];
if(!vis2[i-][j])vis2[i][j]=tot2++;
else vis2[i][j]=vis2[i-][j];
}
}
}
memset(G,,sizeof(G));
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
if(mat[i][j]=='*')
G[vis1[i][j]][vis2[i][j]]=;
}
}
n=max(tot1,tot2);
printf("%d\n",solve());
}
return ;
}

POJ 2226.Muddy Fields-二分图最大匹配(最小点覆盖)的更多相关文章

  1. [POJ] 2226 Muddy Fields(二分图最小点覆盖)

    题目地址:http://poj.org/problem?id=2226 二分图的题目关键在于建图.因为“*”的地方只有两种木板覆盖方式:水平或竖直,所以运用这种方式进行二分.首先按行排列,算出每个&q ...

  2. poj 2226 Muddy Fields (二分图)

    大意:给定n*m网格, 每个格子为泥地或草地, 可以用一些长度任意宽度为1的木板盖住泥地, 要求不能盖到草地, 求最少要多少块木板能盖住所有泥地. 最小点覆盖板子题, 建图跑最大匹配即可. #incl ...

  3. POJ 2226 Muddy Fields 二分图(难点在于建图)

    题意:给定一个矩阵和它的N行M列,其中有一些地方有水,现在有一些长度任意,宽为1的木板,要求在板不跨越草,用一些木板盖住这些有水的地方,问至少需要几块板子? 思路:首先想到如果没有不准跨越草的条件则跟 ...

  4. POJ 2226 Muddy Fields(最小顶点覆盖)

    POJ 2226 Muddy Fields 题目链接 题意:给定一个图,要求用纸片去覆盖'*'的位置.纸片能够重叠.可是不能放到'.'的位置,为最少须要几个纸片 思路:二分图匹配求最小点覆盖.和放车那 ...

  5. poj 2226 Muddy Fields(最小点覆盖)

    题意: M*N的矩阵,每个格不是*就是#.     *代表水坑,#代表草地. 农民要每次可以用一块宽为1,长不限的木板去铺这个矩阵.要求这块木板不能覆盖草地.木板可以重复覆盖(即一块木板与另一块木板有 ...

  6. poj 2226 Muddy Fields (转化成二分图的最小覆盖)

    http://poj.org/problem?id=2226 Muddy Fields Time Limit: 1000MS   Memory Limit: 65536K Total Submissi ...

  7. POJ - 2226 Muddy Fields (最小顶点覆盖)

    *.*. .*** ***. ..*. 题意:有一个N*M的像素图,现在问最少能用几块1*k的木条覆盖所有的 * 点,k为>=1的任意值. 分析:和小行星那题很像.小行星那题是将一整行(列)看作 ...

  8. poj 2226 Muddy Fields(最小覆盖点+构图)

    http://poj.org/problem?id=2226 Muddy Fields Time Limit: 1000MS   Memory Limit: 65536K Total Submissi ...

  9. POJ 2226 Muddy Fields (最小点覆盖集,对比POJ 3041)

    题意 给出的是N*M的矩阵,同样是有障碍的格子,要求每次只能消除一行或一列中连续的格子,最少消除多少次可以全部清除. 思路 相当于POJ 3041升级版,不同之处在于这次不能一列一行全部消掉,那些非障 ...

随机推荐

  1. laravel5.5队列

    目录 简单实例 1. 简介和配置 1.1 好处 1.2 配置文件 1.3 队列驱动的必要配置 2. 创建任务 2.1 生成任务类 2.2 修改任务类 2.3 分发任务 2.4 自定义队列 & ...

  2. Pascal游戏 大富翁MUD

    大富翁MUD Pascal源码 Chaobs改编自百度网友作品 此源码非Chaobs原创,但转载时请仍注明出处. 估计90后以后就没有孩子知道MUD了. program wxtw; uses crt; ...

  3. Java 遍历Map集合的方法

    方法一:通过Map.keySet,遍历key和value Map<String, Object> map = new HashMap<>(); for (String key ...

  4. Kotlin中功能操作与集合(KAD 11)

    作者:Antonio Leiva 时间:Feb 2, 2017 原文链接:https://antonioleiva.com/functional-operations-collections-kotl ...

  5. ASP.NET Core 认证与授权[2]:Cookie认证 (笔记)

    原文链接:https://www.cnblogs.com/RainingNight/p/cookie-authentication-in-asp-net-core.html 由于HTTP协议是无状态的 ...

  6. Oz 创建CentOS7镜像

    参考链接: https://github.com/clalancette/oz/wiki/Oz-template-description-language https://github.com/cla ...

  7. 转:npm install 时总是报phantomjs-prebuilt@2.1.14安装失败

    该文章转自:http://www.cnblogs.com/alice626/p/6206722.html 在npm install时总是报如下错误, 尝试单独安装:npm install phanto ...

  8. NodeJS05

    商品分类模块 分类model const mongoose = require('mongoose') const schema = new mongoose.Schema({ name: { typ ...

  9. linux 环境下mysql忽略大小写

    mysql数据库在window环境下默认是忽略大小写的,而linux环境中则相反,数据库移植过去后可能会影响到应用工程的正常使用. 解决方法: 用root帐号登录后,在/etc/my.cnf 中的[m ...

  10. Linux networkmanager

    我们开发的网络,出于保密,只能叫XXX网络,或者我更倾向于称之为WTF-network 由于经常处于封闭的环境,刚一接触新一点的世界,总是有那么一点猝不及防.最近发现配置的静态路由经常消失,经发现是n ...