Muddy Fields
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 10961   Accepted: 4071

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

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
const int N=;
char mp[N][N];
int used[N*N],head[N*N],tot,n,m;
struct node
{
int to,next;
} e[];
bool vis[N*N];
int aa[N][N],bb[N][N],a,b;
void add(int u,int v)
{
e[tot].to=v;
e[tot].next=head[u];
head[u]=tot++;
}
bool findx(int u)
{
for(int i=head[u]; ~i; i=e[i].next)
{
int v=e[i].to;
if(vis[v]) continue;
vis[v]=;
if(!used[v]||findx(used[v]))
{
used[v]=u;
return true;
}
}
return false;
}
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
int maxmatch=;
tot=;
a=b=;
memset(head,-,sizeof(head));
memset(aa,,sizeof(aa));
memset(bb,,sizeof(bb));
for(int i=; i<=n; ++i) scanf("%s",mp[i]+);
for(int i=; i<=n; ++i) for(int j=; j<=m; ++j)
{
bool c=;
while(mp[i][j]=='*'&&j<=m) c=,aa[i][j++]=a;
if(c) ++a;
}
for(int i=; i<=m; ++i) for(int j=; j<=n; ++j)
{
bool c=;
while(mp[j][i]=='*'&&j<=n) c=,bb[j++][i]=b;
if(c) ++b;
}
for(int i=; i<=n; ++i) for(int j=; j<=m; ++j) if(aa[i][j]) add(aa[i][j],bb[i][j]);
memset(used,,sizeof(used));
for(int i=; i<a; ++i)
{
memset(vis,,sizeof(vis));
if(findx(i)) ++maxmatch;
}
printf("%d\n",maxmatch);
}
}

poj2226更改行列匹配建图的更多相关文章

  1. HDU 3036 Escape 网格图多人逃生 网络流||二分匹配 建图技巧

    题意: 每一个' . '有一个姑娘, E是出口,'.'是空地 , 'X' 是墙. 每秒钟每一个姑娘能够走一步(上下左右) 每秒钟每一个出口仅仅能出去一个人 给定n*m的地图, 时限T 问全部姑娘是否能 ...

  2. TTTTTTTTTTTTTTTTT POJ 2226 草地覆木板 二分匹配 建图

    Muddy Fields Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9754   Accepted: 3618 Desc ...

  3. TTTTTTTTTTTTTTTTTT POJ 2724 奶酪消毒机 二分匹配 建图 比较难想

    Purifying Machine Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 5004   Accepted: 1444 ...

  4. Antenna Placement POJ - 3020 二分图匹配 匈牙利 拆点建图 最小路径覆盖

    题意:图没什么用  给出一个地图 地图上有 点 一次可以覆盖2个连续 的点( 左右 或者 上下表示连续)问最少几条边可以使得每个点都被覆盖 最小路径覆盖       最小路径覆盖=|G|-最大匹配数 ...

  5. POJ-3020 Antenna Placement---二分图匹配&最小路径覆盖&建图

    题目链接: https://vjudge.net/problem/POJ-3020 题目大意: 一个n*m的方阵 一个雷达可覆盖两个*,一个*可与四周的一个*被覆盖,一个*可被多个雷达覆盖问至少需要多 ...

  6. kuangbin带你飞 匹配问题 二分匹配 + 二分图多重匹配 + 二分图最大权匹配 + 一般图匹配带花树

    二分匹配:二分图的一些性质 二分图又称作二部图,是图论中的一种特殊模型. 设G=(V,E)是一个无向图,如果顶点V可分割为两个互不相交的子集(A,B),并且图中的每条边(i,j)所关联的两个顶点i和j ...

  7. HDU 1045 Fire Net(行列匹配变形+缩点建图)

    题意:n*n的棋盘上放置房子.同一方同一列不能有两个,除非他们之间被墙隔开,这种话. 把原始图分别按行和列缩点 建图:横竖分区.先看每一列.同一列相连的空地同一时候看成一个点,显然这种区域不可以同一时 ...

  8. (匹配 二维建图) Antenna Placement --POJ --3020

    链接: http://poj.org/problem?id=3020 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82834#probl ...

  9. Card Game Cheater---hdu1528(扑克建图求二分匹配)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1528 题意就是给有两个人有n张牌第二个人知道第一个人的牌的序列: 然后第二个人尽可能的让自己得更高的分 ...

随机推荐

  1. Linux运维基础阶段部分复习概要

    [jj@oldboy ~]$ hostnamectl set-hostname zj 主机名只有root用户才有权限修改,普通用户想要修改要知道root密码,sudo提权,重启虚拟机或者打开新的窗口新 ...

  2. 蘑菇街CEO陈琪上市致辞:科技是生产力 美丽也是生产力

    雷帝网 乐天 12月7日报道 蘑菇街CEO陈琪今日在纽交所上市致辞时表示,蘑菇街的使命是让时尚触手可及,立志成为最领先的时尚目的地,并把"科技是生产力,美丽也是生产力"作为蘑菇街价 ...

  3. Linux 查看进程资源--ps、top命令

    1,ps命令 ps能够给出当前系统中进程的快照.它能捕获系统在某一事件的进程状态 命令参数:          a                                      显示所有进 ...

  4. STL训练 HDU - 1716 Ray又对数字的列产生了兴趣:

    HDU - 1716 Ray又对数字的列产生了兴趣: 现有四张卡片,用这四张卡片能排列出很多不同的4位数,要求按从小到大的顺序输出这些4位数. Input 每组数据占一行,代表四张卡片上的数字(0&l ...

  5. Codeforce 140C (贪心+优先队列)补题

    C. New Year Snowmen time limit per test2 seconds memory limit per test256 megabytes inputstandard in ...

  6. ASP.NET MVC使用log4net

    本文介绍如何在ASP.NET MVC中使用log4net来记录日志文件. 参考链接:https://www.codeproject.com/Articles/823247/How-to-use-Apa ...

  7. python基础的一些题目

    第一部分: 第二部分: 第三部分:

  8. Java面试题:String、StringBuilder、StringBuffer区别

    String:不可变字符序列. StringBuilder:可变字符序列.效率高.线程不安全,适合单线程. StringBuffer:可变字符序列.效率低.线程安全,适合多线程. 效率从高到低:Str ...

  9. php使用curl post josn数据

    今天在工作中使用到要使用("Content-Type", "application/json;charset=UTF-8")格式传送和接受数据,再次做个记录 p ...

  10. maven项目变成web项目

    具体步骤如图所示: 第一步:建议一个Maven Webapp项目  第二步:右击项目,选择属性,找到project facets,点击tuntimes标签选择apache tomcat v6.0选中P ...