Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 10149   Accepted: 3783

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.

Source

将连续的一段横/纵条算作同一个,若横纵条相交则连边,跑二分图匹配。

 /*by SilverN*/
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
using namespace std;
const int mxn=;
int m,n;
char a[mxn][mxn];
//
int idx,idy;
int hs[mxn][mxn];
int link[mxn];
int mp[mxn][mxn];
bool vis[mxn];
//
void init(){
int i,j;
for(i=;i<=n;i++){
for(j=;j<=m;j++){
if(a[i][j]=='*'){
++idx;
while(a[i][j]=='*')hs[i][j++]=idx;
}
}
}
idy=idx;
for(j=;j<=m;j++)
for(i=;i<=n;i++){
if(a[i][j]=='*'){
++idy;
while(a[i][j]=='*'){
mp[idy][hs[i][j]]=;
mp[hs[i++][j]][idy]=;
}
}
}
return;
}
bool DFS(int u){
for(int i=;i<=idy;i++)
if(!vis[i] && mp[u][i]){
vis[i]=;
if(link[i]==- || DFS(link[i])){
link[i]=u;
return ;
}
}
return ;
}
int ans=;
void solve(){
memset(link,-,sizeof link);
for(int i=;i<=idx;i++){
memset(vis,,sizeof vis);
if(DFS(i))ans++;
}
return;
}
int main(){
scanf("%d%d",&n,&m);
int i,j;
for(i=;i<=n;i++)
scanf("%s",a[i]+);
init();
solve();
printf("%d\n",ans);
return ;
}

POJ2226 Muddy Fields的更多相关文章

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

    题目:http://poj.org/problem?id=2226 题意:给你一个字符矩阵,每个位置只能有"*"或者“.",连续的横着或者竖的“*"可以用一块木 ...

  2. POJ2226 Muddy Fields(二分图最小点覆盖集)

    题目给张R×C的地图,地图上*表示泥地..表示草地,问最少要几块宽1长任意木板才能盖住所有泥地,木板可以重合但不能盖住草地. 把所有行和列连续的泥地(可以放一块木板铺满的)看作点且行和列连续泥地分别作 ...

  3. POJ2226 Muddy Fields 二分匹配 最小顶点覆盖 好题

    在一个n*m的草地上,.代表草地,*代表水,现在要用宽度为1,长度不限的木板盖住水, 木板可以重叠,但是所有的草地都不能被木板覆盖. 问至少需要的木板数. 这类题的建图方法: 把矩阵作为一个二分图,以 ...

  4. poj2226 Muddy Fields 填充棒子(二分匹配)

    参考博客:https://blog.csdn.net/liujc_/article/details/51287019 参考博客:https://blog.csdn.net/acdreamers/art ...

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

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

  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(最小顶点覆盖)

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

  8. Muddy Fields

     Muddy Fields Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submi ...

  9. bzoj 1735: [Usaco2005 jan]Muddy Fields 泥泞的牧场 最小点覆盖

    链接 1735: [Usaco2005 jan]Muddy Fields 泥泞的牧场 思路 这就是个上一篇的稍微麻烦版(是变脸版,其实没麻烦) 用边长为1的模板覆盖地图上的没有长草的土地,不能覆盖草地 ...

随机推荐

  1. 通过TTL值判断系统

    我们做网络的渗透测试,开始的时候会ping一下网站判断一下网站使用的系统,默认情况下, UNIX 255 LINUX 64WIN2K/NT 128WINDOWS 32 但是 每经过一个路由器就会减1这 ...

  2. [1]Telerik Extensions for ASP.NET MVC 中文教程(转)

    http://demos.telerik.com/aspnet-mvc/ Telerik Extensions for ASP.NET MVC 是Telerik 公司专门针对Asp.net MVC 开 ...

  3. C# 调用C++/MFC写的dll

    C#调用C++的非托管类的dll其实很简单基本就是固定的调用格式. dll的编写,首先是打开VS新建一个C++的控制台程序,下一步后选择dll以及空文档即可.然后就是添加一个类添加一个方法.方法排头固 ...

  4. ASP.NET错误处理的方式(总结)

    转载至: http://www.cnblogs.com/chinhr/archive/2007/06/26/795947.html ASP.NET错误处理的方式(整理&总结)英文文章研究:ht ...

  5. H5实现拍照并上传

    <!DOCTYPE HTML><html><head>    <meta charset="UTF-8">    <meta ...

  6. Android调用蓝牙打印机

    首先需要一个jar包,bluesdk,请自行百度. 具体排版样式跟网络打印机打印排版样式实现一样,这里不多叙述,只贴一个实现方法代码.蓝牙打印机使用前需要先跟手机配对,可以保存在本地,记录下地址,这里 ...

  7. Jenkins进阶系列之——14配置Jenkins用户和权限

    今天给大家说说使用Jenkins专有用户数据库的配置,和一些常用的权限配置. 配置用户注册 在已运行的Jenkins主页中,点击左侧的系统管理—>Configure Global Securit ...

  8. 疯狂位图之——位图生成12GB无重复随机乱序大整数集

    上一篇讲述了用位图实现无重复数据的排序,排序算法一下就写好了,想弄个大点数据测试一下,因为小数据在内存中快排已经很快. 一.生成的数据集要求 1.数据为0--2147483647(2^31-1)范围内 ...

  9. WIN8 浏览器排版不兼容问题

    经常访问网站失败 访问部分网站只显示白底蓝字没有排版也没有图片 尝试了网上的各种方法,也是用了360和百度安全管家的网页修复 重置了IE设置 都不行!!! 最后有效的方法是 更换DNS 208.67. ...

  10. Android 中R文件丢失问题解决方案

    Project → clean 项目上右键→android Tools→ fix project 检查xml文件中有无命名错误,特别是@+id写成@id的[特别是这条,注意看控制台打印的xml错误]