题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=654

Robert is a famous engineer. One day he was given a task by his boss. The background of the task was the following:



Given a map consisting of square blocks. There were three kinds of blocks: Wall, Grass, and Empty. His boss wanted to place as many robots as possible in the map. Each robot held a laser weapon which could shoot to four directions (north, east, south, west)
simultaneously. A robot had to stay at the block where it was initially placed all the time and to keep firing all the time. The laser beams certainly could pass the grid of Grass, but could not pass the grid of Wall. A robot could only be placed in an Empty
block. Surely the boss would not want to see one robot hurting another. In other words, two robots must not be placed in one line (horizontally or vertically) unless there is a Wall between them.



Now that you are such a smart programmer and one of Robert's best friends, He is asking you to help him solving this problem. That is, given the description of a map, compute the maximum number of robots that can be placed in the map.



Input




The first line contains an integer T (<= 11) which is the number of test cases. 



For each test case, the first line contains two integers m and n (1<= m, n <=50) which are the row and column sizes of the map. Then m lines follow, each contains n characters of '#', '*', or 'o' which represent Wall, Grass, and Empty, respectively.

Output



For each test case, first output the case number in one line, in the format: "Case :id" where id is the test case number, counting from 1. In the second line just output the maximum number of robots that can be placed in that map.

Sample Input

2

4 4

o***

*###

oo#o

***o

4 4

#ooo

o#oo

oo#o

***#

Sample Output

Case :1

3

Case :2

5


Author: XU, Luchuan

Source: ZOJ Monthly, October 2003

PS:

http://blog.csdn.net/acdreamers/article/details/8654005

这图要用邻接表。 否则会爆内存。

50*50/2! 开1500的二维就OK拉。

代码例如以下:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
#define MAXN 1547
int LN, RN;//L,R数目
int g[MAXN][MAXN], linker[MAXN];
bool used[MAXN];
char ma[57][57];
int r[MAXN][MAXN], c[MAXN][MAXN];
int head[MAXN];
struct node
{
int x;
int next;
} edge[MAXN<<1];
int cnt = 1;
void addEdge(int x, int y)
{
edge[cnt].x = y;
edge[cnt].next = head[x];
head[x] = cnt++;
}
int dfs(int L)//从左边開始找增广路径
{
int R;
//for(R = 1; R <= RN; R++)
for(int i = head[L]; ~i; i = edge[i].next)
{
R = edge[i].x;
if(!used[R])
{
//找增广路。反向
used[R]=true;
if(linker[R] == -1 || dfs(linker[R]))
{
linker[R] = L;
return 1;
}
}
}
return 0;
}
int hungary()
{
int res = 0 ;
int L;
memset(linker,-1,sizeof(linker));
for( L = 1; L <= LN; L++)
{
memset(used,0,sizeof(used));
if(dfs(L) != 0)
res++;
}
return res;
} int check(int x, int y)
{
if(ma[x][y]=='o' || ma[x][y]=='*')
{
return 1;
}
return 0;
}
void init()
{
cnt = 0;
memset(head,-1,sizeof(head));
memset(g,0,sizeof(g));
memset(c,0,sizeof(c));
memset(r,0,sizeof(r));
}
int main()
{
int t;
int n, m;
int k, L, R; int cas = 0;
scanf("%d",&t);
while(t--)
{
init();
scanf("%d%d",&n,&m);
for(int i = 1; i <= n; i++)
{
scanf("%s",ma[i]+1);
} int cnt1 = 1, cnt2 = 1;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
{
if(check(i, j))
{
if(r[i][j] == 0)//行
{
for(int k = j; k <= m; k++)
{
if(check(i, k))
{
r[i][k] = cnt1;
}
else
{
break;
}
}
cnt1++;
}
if(c[i][j] == 0)//列
{
for(int k = i; k <= n; k++)
{
if(check(k, j))
{
c[k][j] = cnt2;
}
else
{
break;
}
}
cnt2++;
}
}
}
}
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
{
if(r[i][j] && c[i][j] && ma[i][j]=='o')
{
//g[r[i][j]][c[i][j]] = 1;
//g[c[i][j]][r[i][j]] = 1;
addEdge(r[i][j], c[i][j]);
}
}
}
LN = cnt1;
RN = cnt2;
int ans = hungary();
printf("Case :%d\n",++cas);
printf("%d\n",ans);
}
return 0 ;
}
/*
2
4 4
o***
*###
oo#o
***o
4 4
#ooo
o#oo
oo#o
***#
*/

最新文章

  1. ubuntu 14.04LTS 环境下配置NFS服务
  2. ndk学习8: 编译动态库
  3. 在CentOS6.7操作系统上编译安装mysql-5.6.31
  4. HDU 5212 Code
  5. java提高篇---HashSet
  6. android部分手机onclick事件触发2次
  7. Introduction into ISO 27145 WWH-OBD
  8. jQuery中的选择器&lt;思维导图&gt;
  9. Python变量类型(l整型,长整形,浮点型,复数,列表,元组,字典)学习
  10. FZU-1921+线段树
  11. hdu 1847 Good Luck in CET-4 Everybody! 博弈论
  12. vim 退出保留显示的内容
  13. 第一次用Github desktop(mac)提交代码遇到的问题
  14. Linux命令之查找
  15. MyBatis浅尝笔记
  16. 从RGB色转为灰度色算法
  17. CentOS上安装Git服务器
  18. nuxt 运行项目后 中总是报错
  19. linux常用命令随记
  20. MVC5 框架 配置 盘古分词

热门文章

  1. 路飞学城Python-Day14
  2. anaconda安装basemap
  3. (WC2018模拟十二)【FJOI2016集训Day7T3】Xor-Mul棋盘
  4. [置顶] Netty学习总结(1)——Netty入门介绍
  5. [terry笔记]ogg_迁移同步实验_零停机
  6. Android OpenGL ES(七)----理解纹理与纹理过滤
  7. 【POJ 2750】 Potted Flower(线段树套dp)
  8. zzulioj--1817--match number(水题)
  9. FZOJ--2221-- RunningMan(水题)
  10. [NOI2013模拟] BZOJ4705 棋盘游戏 解题报告(组合计数)