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 ;
}

最新文章

  1. SVN图形管理工具-Submint
  2. 背景图片与 CSS的那些事
  3. java事务的类型——面试被问到
  4. [Flex] PopUpButton系列——CornerRadius的运用
  5. Umbraco(6)-Creating More Pages Using the Master - Part 2(翻译文档)
  6. 【转】Nginx系列(五)--nginx+tomcat实现负载均衡
  7. C# Process 类的思考
  8. 提高matlab运行速度和节省空间的心得
  9. C#数字图像处理的3种方法
  10. c语言结构体2之变量赋值于字符串
  11. 解决Timer回调方法重复调用的问题
  12. php和js中,utf-8编码转成base64编码
  13. Dev中GridControl的导出Excel设置
  14. android初学
  15. 洛谷P4389 付公主的背包 [生成函数,NTT]
  16. SQL查询语句,怎样查询重复数据
  17. Dapper Extensions Change Schema
  18. jqGrid 获取多级标题表头
  19. formidable处理多文件上传
  20. THP Transparent HugePages 相关知识与关闭【转】

热门文章

  1. 我的Unity学习路线
  2. C# 读取Excel
  3. 转: CentOS 6.4安装pip,CentOS安装python包管理安装工具pip的方法
  4. Eclipse快捷键列表大全
  5. Block 的基本用法
  6. 事故记录-过多进程致使CPU卡死
  7. Android studio导入eclipse项目混淆打包出错
  8. JQuery判断数组中是否包含某个元素$.inArray(&quot;js&quot;, arr);
  9. android布局 FrameLayout(帧布局)详解
  10. 20145208 《Java程序设计》第一周学习总结