用户ID: 密码: 验证:

登 录

注 册 取回密码

中山教育

中山国际网

中国教育在线

时代财富科技公司 FortuneAge Technology Co., Ltd. 校园博客客服网站(新)

我的资料

Mpq

博客信息

积分:988
等级:4级 lv 4
日志总数:231
发表评论总数:18 ( 查看)
获得评论总数:21
发表留言总数:0
所属学校:三鑫
收藏本站:

最新公告

欢迎光临我的博客!

最新相册

我的日历

最新评论

--游客
好文好文,是您的手笔?如果是您的文章,如果您愿意和我联系,...
还有就是数学不能使用计算器…….......在读初中之前原...
--Mpq
这次似乎不举行冬季长跑……看来在三鑫参加的体育项目最终是以...
--Mpq
看了你的"总结", 挺有针对性的! 相信下学期你一定会有...

RSS


首页 -> 经典算法->二分图匹配
二分图匹配

Place the Robots

Time limit: 5 Seconds   Memory limit: 32768K  
Total Submit: 1112   Accepted Submit: 276  

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
 
Program Robots_Mpq;

Const Maxt=1250;

var
  i,n,m,x,y,t,Ans:integer;
  cy:array[1..Maxt] of integer;
  sy:array[1..Maxt] of boolean;
  a:array[0..51,0..51] of integer;
  h,s:array[1..50,1..50] of integer;
  g:array[1..Maxt,1..Maxt] of boolean;

procedure init;
var
  ch:char;
  i,j:integer;
begin
  readln(n,m);
  for i:=0 to n+1 do
    for j:=0 to m+1 do a[i,j]:=2;

  for i:=1 to n do
  begin
    for j:=1 to m do
    begin
      read(ch);
      case ch of
        '*':a[i,j]:=1;
        'o':a[i,j]:=0;
        '#':a[i,j]:=2;
      end;
    end;
    readln;
  end;

  x:=0; y:=0;
  for i:=1 to n do
  begin
    j:=1;
    while a[i,j]=2 do inc(j);
    for j:=j to m do
    begin
      if (a[i,j-1]=2) and (a[i,j]<>2) then inc(x);
      h[i,j]:=x;
    end;
  end;

  for j:=1 to m do
  begin
    i:=1;
    while a[i,j]=2 do inc(i);
    for i:=i to n do
    begin
      if (a[i-1,j]=2) and (a[i,j]<>2) then inc(y);
      s[i,j]:=y;
    end;
  end;

  fillchar(g,sizeof(g),0);
  for i:=1 to n do
    for j:=1 to m do
      if a[i,j]=0 then
        g[h[i,j],s[i,j]]:=true;
end;

Function Find(k:integer):boolean;
var
  i:integer;
begin
  for i:=1 to y do
    if (not sy[i]) and (g[k,i]) then
    begin
      sy[i]:=true;
      if (cy[i]=0) or (Find(cy[i])) then
      begin
        cy[i]:=k;
        exit(true);
      end;
    end;
  exit(false);
end;

procedure KM;
var
  i:integer;
begin
  fillchar(cy,sizeof(cy),0);
  Ans:=0;
  for i:=1 to x do
  begin
    fillchar(sy,sizeof(sy),0);
    if Find(i) then inc(Ans);
  end;
  writeln(Ans);
end;

begin
assign(input,'robots.in'); reset(input);
assign(output,'robots.out'); rewrite(output);
  readln(t);
  for i:=1 to t do
  begin
    init;
    KM;
  end;
close(input); close(output);
end.

网友评论

共 0 页,0 条记录  

用户名:
密码:
您的评论:
正在载入编辑器...
请输入验证码:


发 表 评 论

Mpq-中山教师家园