Fire Net

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7929    Accepted Submission(s):
4521

Problem Description
Suppose that we have a square city with straight
streets. A map of a city is a square board with n rows and n columns, each
representing a street or a piece of wall.

A blockhouse is a small castle
that has four openings through which to shoot. The four openings are facing
North, East, South, and West, respectively. There will be one machine gun
shooting through each opening.

Here we assume that a bullet is so
powerful that it can run across any distance and destroy a blockhouse on its
way. On the other hand, a wall is so strongly built that can stop the bullets.

The goal is to place as many blockhouses in a city as possible so that
no two can destroy each other. A configuration of blockhouses is legal provided
that no two blockhouses are on the same horizontal row or vertical column in a
map unless there is at least one wall separating them. In this problem we will
consider small square cities (at most 4x4) that contain walls through which
bullets cannot run through.

The following image shows five pictures of
the same board. The first picture is the empty board, the second and third
pictures show legal configurations, and the fourth and fifth pictures show
illegal configurations. For this board, the maximum number of blockhouses in a
legal configuration is 5; the second picture shows one way to do it, but there
are several other ways.

Your
task is to write a program that, given a description of a map, calculates the
maximum number of blockhouses that can be placed in the city in a legal
configuration.

 
Input
The input file contains one or more map descriptions,
followed by a line containing the number 0 that signals the end of the file.
Each map description begins with a line containing a positive integer n that is
the size of the city; n will be at most 4. The next n lines each describe one
row of the map, with a '.' indicating an open space and an uppercase 'X'
indicating a wall. There are no spaces in the input file.
 
Output
For each test case, output one line containing the
maximum number of blockhouses that can be placed in the city in a legal
configuration.
 
Sample Input
4
.X..
....
XX..
....
2
XX
.X
3
.X.
X.X
.X.
3
...
.XX
.XX
4
....
....
....
....
0
 
 
 
 
Sample Output
5
1
5
2
4
 
用深搜对每一个点进行遍历,
 
 #include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char map[][];
int n,now,ibest,current;
bool canput(int row,int col)//判断能不能放
{
int i;
for(i=row-;i>=;i--)//判断行
{
if(map[i][col]=='O')
return false;
if(map[i][col]=='X')
break;
}
for(i=col-;i>=;i--)//判断列
{
if(map[row][i]=='O')
return false;
if(map[row][i]=='X')
break;
}
return true;
}
void dfs(int k,int current)
{
int x,y;
if(k==n*n)//如果遍历完就返回
{
if(current>ibest)//更新最大的个数
ibest=current;
return ;
}
else
{
x=k/n;
y=k%n;
if(map[x][y]=='.'&&canput(x,y))
{
map[x][y]='O';
dfs(k+,current+);//下一次递归
map[x][y]='.';
}
dfs(k+,current);//当前不放碉堡
}
}
int main()
{
while(scanf("%d",&n),n)
{
getchar();
int k=,i;
ibest=;
current=;
for(i=;i<n;i++)
scanf("%s",map[i]);
dfs(,);
printf("%d\n",ibest);
}
return ;
}

Fire Net--hdu1045的更多相关文章

  1. HDU1045 Fire Net(DFS)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1045 Fire Net Time Limit: 2000/1000 MS (Java/Others)  ...

  2. HDU-1045 Fire Net

    http://acm.hdu.edu.cn/showproblem.php?pid=1045 Fire Net Time Limit: 2000/1000 MS (Java/Others)    Me ...

  3. HDU1045 Fire Net(DFS枚举||二分图匹配) 2016-07-24 13:23 99人阅读 评论(0) 收藏

    Fire Net Problem Description Suppose that we have a square city with straight streets. A map of a ci ...

  4. HDU1045:Fire Net(二分图匹配 / DFS)

    Fire Net Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  5. HDU1045 Fire Net —— 二分图最大匹配

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1045 Fire Net Time Limit: 2000/1000 MS (Java/Others)  ...

  6. hdu-1045.fire net(缩点 + 二分匹配)

    Fire Net Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  7. hdu1045 Fire Net

    在一张地图上建立碉堡(X),要求每行没列不能放两个,除非中间有强挡着.求最多能放多少个碉堡 #include<iostream> #include<cstdio> #inclu ...

  8. hdu1045 Fire Net---二进制枚举子集

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1045 题目大意: 给你一幅n*n的图,再给你一些点,这些点的上下左右不能再放其他点,除非有墙('X') ...

  9. 【HDU-1045,Fire Net-纯暴力简单DFS】

    原题链接:点击!   大致题意:白块表示可以放置炮台的位置——每个炮台可以攻击到上下左右的直线上的炮台(也就是说在它的上下左右直线上不可以再放置炮台,避免引起互相攻击),黑块表示隔离墙的位置——不可放 ...

  10. Fire Net(HDU-1045)(匈牙利最大匹配)(建图方式)

    题意 有一个 n*n 的图,. 代表空白区域,X 代表墙,现在要在空白区域放置结点,要求同一行同一列只能放一个,除非有墙阻隔,问最多能放多少个点 思路 只有在墙的阻隔情况下,才会出现一行/列出现多个点 ...

随机推荐

  1. information_schema.key_column_usage 学习

    information_schema.key_column_usage 表可以查看索引列上的约束: 1.information_schema.key_column_usage 的常用列: 1.cons ...

  2. ansilbe 入门001、ansible的介绍

    概述: ansible 作为一个配置管理工具.首先我们要“告诉”它管理的是那几台机器啊:而这个信息就在要ansible 的配置文件中体现了.默认情况下ansible的配置文件保存在 /etc/ansi ...

  3. 嵌入式系统USB CDROM虚拟光驱驱动程序开发

    带U盘功能的的USB接口设备已经越来越常见了.如果能够把产品说明书或者产品设备驱动程序做成一个USB CDROM,那该多方便.假设:你已经有了USB mass storage驱动.你的任务是在此基础上 ...

  4. 数据的加密传输——单片机上实现TEA加密解密算法

    各位大侠在做数据传输时,有没有考虑过把数据加密起来进行传输,若在串口或者无线中把所要传的数据加密起来,岂不是增加了通信的安全性.常用的加密解密算法比如DES.RSA等,受限于单片机的内存和运算速度,实 ...

  5. libevent for qt网络模块

    libevent for qt网络模块,直接替换qt的select模型,支持epoll,select,pool.使用非常简单,无需修改以前的代码结构 最近在开发im服务器,需要大并发链接.QT默认的是 ...

  6. Apache Commons Pool 故事一则

    Apache Commons Pool 故事一则 最近工作中遇到一个由于对commons-pool的使用不当而引发的问题,习得正确的使用姿势后,写下这个简单的故事,帮助理解Apache Commons ...

  7. loadlibrary(xxx.dll) 失败 返回14001 由于应用程序配置不正确 应用程序未能启动.重新安装应用程序可能会纠正这个问 .

    欢迎大家拍砖! 一.应用背景 有一个在win7中用VS2008编译成功,运行正常的程序:Exe+DLL; 放到XP虚拟镜像上运行却提示:LoadLibrary返回14001. (1) 后来采用了下面方 ...

  8. 如何理解 css3 的 perspective 属性

    一.写在前面的话 最近想多了解一下CSS3的transform 3D效果,transform:英文直译就是转换,它可以实现旋转.缩放.位移等效果,听起来有没有觉得很酷的样子,狠狠的点这里来看看旋转和位 ...

  9. LeeCode(Database)-Employees Earning More Than Their Managers

    The Employee table holds all employees including their managers. Every employee has an Id, and there ...

  10. ZOJ(3455)

    Shizuka's Letter Time Limit: 2 Seconds      Memory Limit: 65536 KB Nobita receives a letter from Shi ...