HDU-1045 Fire Net
http://acm.hdu.edu.cn/showproblem.php?pid=1045
Fire Net
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6756 Accepted Submission(s): 3829
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.
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int n,c[][];
char str[][];
int map[][];
int mmax;
bool judge(int row,int col) //判断是否可以放置
{ //在遇到墙之前同行或同列上已放置,则不能再放
int i;
for(i=col-;i>=;i--)
{
if(map[row][i]==) return false;
if(str[row][i]=='X') break;
} for(i=row-;i>=;i--)
{
if(map[i][col]==) return false;
if(str[i][col]=='X') break;
} return true;
}
void dfs(int x,int y,int num)
{
if(x==n)
{
if(num>mmax)
mmax=num;
return ;
}
else
{
// printf("x=%d,y=%d,num=%d\n",x,y,num);
if(y<n)
{
if(str[x][y]=='.'&&judge(x,y))
{
map[x][y]=;
dfs(x,y+,num+);
map[x][y]=;
}
dfs(x,y+,num);
}
else
dfs(x+,,num); }
}
int main()
{
while(~scanf("%d",&n))
{
int i;
memset(map,,sizeof(map));
if(n==)
break;
mmax=;
for(i=; i<n; i++)
scanf("%s",str[i]);
dfs(,,);
printf("%d\n",mmax);
}
return ;
}
HDU-1045 Fire Net的更多相关文章
- HDOJ(HDU).1045 Fire Net (DFS)
HDOJ(HDU).1045 Fire Net [从零开始DFS(7)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HD ...
- hdu 1045 Fire Net(最小覆盖点+构图(缩点))
http://acm.hdu.edu.cn/showproblem.php?pid=1045 Fire Net Time Limit:1000MS Memory Limit:32768KB ...
- HDU 1045(Fire Net)题解
以防万一,题目原文和链接均附在文末.那么先是题目分析: [一句话题意] 给定大小的棋盘中部分格子存在可以阻止互相攻击的墙,问棋盘中可以放置最多多少个可以横纵攻击炮塔. [题目分析] 这题本来在搜索专题 ...
- HDU 1045 Fire Net 【连通块的压缩 二分图匹配】
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1045 Fire Net Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 1045 Fire Net(dfs,跟8皇后问题很相似)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1045 Fire Net Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 1045——Fire Net——————【最大匹配、构图、邻接矩阵做法】
Fire Net Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Sta ...
- HDU 1045 Fire Net 状压暴力
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1045 Fire Net Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 1045 Fire Net 二分图建图
HDU 1045 题意: 在一个n*n地图中,有许多可以挡住子弹的墙,问最多可以放几个炮台,使得炮台不会相互损害.炮台会向四面发射子弹. 思路: 把行列分开做,先处理行,把同一行中相互联通的点缩成一个 ...
- HDU - 1045 Fire Net(二分匹配)
Description Suppose that we have a square city with straight streets. A map of a city is a square bo ...
- HDU - 1045 Fire Net(搜索)
Description Suppose that we have a square city with straight streets. A map of a city is a square bo ...
随机推荐
- c编程:提示用户输入一个0—9的数字进行猜测电脑产生的随机数。一共有三次机会。
// // main.c // 使用c语言进行编程: 题目:由电脑生成一个由0-9之间的随机数,提示用户也输入一个数字进行猜测.当猜测三次仍不中的时候结束程序. 编译环境:Xcode6.3 特别介 ...
- 配置nginx的负载均衡
1.1 什么是负载均衡 负载均衡 建立在现有网络结构之上,它提供了一种廉价有效透明的方法扩展网络设备和服务器的带宽.增加吞吐量.加强网络数据处理能力.提高网络的灵活性和可用性. 负载均衡,英文名称 ...
- Sql server 浅谈用户定义表类型
1.1 简介 SQL Server 中,用户定义表类型是指用户所定义的表示表结构定义的类型.您可以使用用户定义表类型为存储过程或函数声明表值参数,或者声明您要在批处理中或在存储过程或函数的主体中使用的 ...
- 【原创】解决国内Android SDK无法更新问题更新
使用代理,推荐使用shadowsock 在SDK Manage的tools-options填好代理 服务器地址127.0.0.1 端口1080
- 如何设置 font-family 比较好以及字体的中英文名
如何设置 font-family 比较好? 如果设置为font-family: Arial, "微软雅黑","宋体"; 是不是英文都会使用Arial字体,而中文 ...
- nodejs实现单文件上传。
new了formidable的一个实例. formidable模块可以直接捕获当前数据流的状态并返回文件路径. 主要使用了file事件和end事件. var form = new formidable ...
- centos 忘记 root 密码
采用单用户维护模式可以重设置新密码 系统重启,按任意键进入如下所示的菜单: 选择“kernel /.....”根据提示,按下 "e" 就能进入grup 编辑模式,此时出现的画面类似 ...
- js事件流、事件处理程序/事件侦听器
1.事件流 事件冒泡 IE的事件流叫做事件冒泡(event bubbling),即事件开始时由最具体的元素(文档中嵌套层次最深的那个节点)接收,然后逐级向上传播到较为不具体的节点(文档). 事件捕获 ...
- php发送http请求
http请求有get,post. php发送http请求有三种方式[我所知道的有三种,有其他的告诉我]. file_get_contents();详情见:http://www.cnblogs.com/ ...
- Educational Codeforces Round 6 D. Professor GukiZ and Two Arrays
Professor GukiZ and Two Arrays 题意:两个长度在2000的-1e9~1e9的两个序列a,b(无序);要你最多两次交换元素,使得交换元素后两序列和的差值的绝对值最小:输出这 ...