ZOJ 1002 Fire Net
来源:互联网 发布:淘宝客隐藏优惠券设置 编辑:程序博客网 时间:2024/04/29 08:01
Suppose that we have a square city with straight streets. A mapof a city is a square board with n rows and n columns, eachrepresenting a street or a piece of wall.
A blockhouse is a small castle that has four openings throughwhich to shoot. The four openings are facing North, East, South,and West, respectively. There will be one machine gun shootingthrough each opening.
Here we assume that a bullet is so powerful that it can runacross any distance and destroy a blockhouse on its way. On theother hand, a wall is so strongly built that can stop thebullets.
The goal is to place as many blockhouses in a city aspossible so that no two can destroy each other. A configuration ofblockhouses is legal provided that no two blockhousesare on the same horizontal row or vertical column in a map unlessthere is at least one wall separating them. In this problem we willconsider small square cities (at most 4x4) that contain wallsthrough which bullets cannot run through.
The following image shows five pictures of the same board. Thefirst picture is the empty board, the second and third picturesshow legal configurations, and the fourth and fifth pictures showillegal configurations. For this board, the maximum number ofblockhouses in a legal configuration is 5; the second picture showsone way to do it, but there are several other ways.
Your task is to write a program that, given a description of amap, calculates the maximum number of blockhouses that can beplaced in the city in a legal configuration.
The input file contains one or more map descriptions, followedby a line containing the number 0 that signals the end of the file.Each map description begins with a line containing a positiveinteger n that is the size of the city; n will be atmost 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 inputfile.
For each test case, output one line containing the maximumnumber of blockhouses that can be placed in the city in a legalconfiguration.
Sample input:
4.X......XX......2XX.X3.X.X.X.X.3....XX.XX4................0
Sample output:
51524
Source: Zhejiang University Local Contest2001
源码:
解题报告:
这一题和八皇后是一个题型,先尝试,后回溯,不同的是,八皇后回溯的目的是求共有的方法,而这一题的目的是为了能求出所有的方法中的个数最大值。
每次落下一个blockhouse,判断是否空位,还有判断是否legal。
这一类型的解题模板:
- ZOJ 1002 Fire Net
- Fire Net代码
- Fire Fly
- ZOJ 2536 best balance
- ZOJ 3197 Goole Book
- ZOJ 1078 Palindrom Numbers
- ZOJ 1633 big string
- ZOJ 2239 In Danger
- ZOJ 1091 Knight Moves
- ZOJ 1045 Hang Over
- ZOJ 1003 Crashing Balloon
- ZOJ 1008 Gnome Tetravex
- ZOJ 1019 Illusive Chase
- ZOJ 1025 Wooden Sticks
- ZOJ 1029 Moving Tables
- ZOJ 1058 Currency Exchange
- zoj 1047 Image Perimeters
- zoj 2750 dijkstra()
- hdu 统计难题(1251)
- ZOJ 1633 big string
- ZOJ 2239 In Danger
- matlab 常用函数
- ZOJ 1037 Gridland
- ZOJ 1002 Fire Net
- ZOJ 1091 Knight Moves
- ZOJ 1067 Color Me Less
- ZOJ 1056 The Worm Turns
- 记忆体局苦苦激发居家裤开局营口和他人睡一会
- ZOJ 1045 Hang Over
- ZOJ 1049 I Think&…
- ZOJ 1003 Crashing Balloon
- 网页布局实例————win7自带计算器