博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu1045——Fire Net(二分图+行列匹配)
阅读量:2344 次
发布时间:2019-05-10

本文共 2736 字,大约阅读时间需要 9 分钟。

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 
#include
#include
#include
#include
#include
#include
#include
//#include
#include
#define INF 0x3f3f3f3f#define MAXN 50#define Mod 10001using namespace std;bool vis[MAXN];char mp[MAXN][MAXN];int n,cnt_c,cnt_r;int G[MAXN][MAXN],row[MAXN][MAXN],col[MAXN][MAXN],r[MAXN],c[MAXN]; //匹配路径;int find(int cur){ for(int i=0; i
>mp[i][j]; for(int i=0; i

转载地址:http://ivcvb.baihongyu.com/

你可能感兴趣的文章
JAVA Webservice
查看>>
Hibernate自动生成实体类
查看>>
Java Memcached
查看>>
JAVA WebSpider
查看>>
XML自动建表/存库
查看>>
Java实现Web服务器
查看>>
C# readonly与const的区别
查看>>
MFC 自定义消息的一般过程
查看>>
剖析Windows消息处理机制
查看>>
多线程入门教程(二)基本概念
查看>>
多线程入门教程(三)线程控制
查看>>
多线程入门教程(四)线程间通信
查看>>
多线程入门教程(五)MFC的多线程
查看>>
多线程入门教程(六)综合实例
查看>>
C/C++ 多线程学习心得
查看>>
C/C++四种退出线程的方法
查看>>
多线程编程要点
查看>>
c++CreateEvent函数在多线程中使用及实例
查看>>
c++多线程同步(1)
查看>>
Windows 下 C/C++ 多线程编程入门参考范例
查看>>