亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 學院 > 開發設計 > 正文

hdu1045【dfs】

2019-11-10 17:10:24
字體:
來源:轉載
供稿:網友

Fire Net

Time Limit: 2000/1000 MS (java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 11193 Accepted Submission(s): 6673

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

題意:炮臺不能同行同列存在,除非中間隔著墻 n<=4,直接dfs即可

#include <iostream>#include <string>#include <cstring>#include <cstdio>#include <cmath>#include <cstdlib>#include <algorithm>#include <queue>#include <map>#define MST(s,q) memset(s,q,sizeof(s))#define INF 0x3f3f3f3f#define MAXN 1005using namespace std;char Map[4][4];struct node{ int x, y;} Node[20];int num , ans, n; // num指能放炮臺的位置的數量int move_x[4] = {0, 0, 1, -1}, move_y[4] = {1, -1, 0, 0};bool CanPut(int k) // 第k個點能不能放{ for (int i = 0; i < 4; i++) // 向四個方向遍歷 { int x = Node[k].x + move_x[i]; int y = Node[k].y + move_y[i]; while (x >= 0 && x < n && y >= 0 && y < n) { if (Map[x][y] == 'X') break; else if (Map[x][y] == '#') // 遇到其他炮臺,則不能放 return 0; x += move_x[i]; y += move_y[i]; } } return 1;}void dfs(int x, int V) // 從第0個點開始dfs這num個點{ if (V > ans) ans = V; if (x == num) return; dfs(x + 1, V); // x位置不放炮臺 if (CanPut(x)) // x位置放炮臺 { Map[Node[x].x][Node[x].y] = '#'; dfs(x + 1, V + 1); Map[Node[x].x][Node[x].y] = '.'; }}int main(){ while (cin >> n, n) { for (int i = 0; i < n; i++) scanf("%s", Map[i]); num = 0; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) { if (Map[i][j] == '.') { Node[num].x = i, Node[num].y = j; num++; } } ans = 0; dfs(0, 0); printf("%d/n", ans); }}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
久久av.com| 2019日本中文字幕| 中文字幕精品av| 久久久久久91香蕉国产| 91性高湖久久久久久久久_久久99| 精品国产欧美成人夜夜嗨| 欧美日韩国产中字| 日韩大片免费观看视频播放| 亚洲人午夜精品免费| 日韩国产一区三区| 亚洲人成欧美中文字幕| 精品成人乱色一区二区| 欧美性猛交xxxxx免费看| 日韩欧美国产中文字幕| 日韩精品极品在线观看播放免费视频| 欧美激情a在线| 亚洲国产一区二区三区在线观看| 国产精品第七影院| 国产精品亚洲视频在线观看| 日韩欧美在线中文字幕| 亚洲国产成人精品电影| 欧美伦理91i| 精品亚洲aⅴ在线观看| 91wwwcom在线观看| 欧美亚州一区二区三区| 在线亚洲欧美视频| 色悠悠国产精品| 国产精品免费在线免费| 一区三区二区视频| 日韩一二三在线视频播| 久久久久久久久中文字幕| 日韩精品福利在线| 亚洲黄页视频免费观看| 国产精品老牛影院在线观看| 欧美成人午夜剧场免费观看| 欧美大秀在线观看| 亚洲精品av在线| 国产精品久久久久77777| 欧美日韩国产成人在线| 日韩av免费网站| 亚洲精品电影网站| 国产精品一二三在线| 日韩欧美亚洲国产一区| 奇米影视亚洲狠狠色| 国产精品专区第二| 91av在线视频观看| 日韩欧美在线视频日韩欧美在线视频| 亚洲综合色av| 国产999在线观看| 热久久免费视频精品| 国产日本欧美一区| 欧美日韩视频免费播放| 国产在线精品一区免费香蕉| 欧美乱人伦中文字幕在线| 91精品在线观| 亚洲国产91精品在线观看| 日本精品视频在线| 自拍偷拍免费精品| 欧美老肥婆性猛交视频| 亚洲国产精品久久91精品| 久久久999成人| 欧美成人激情视频| 中文字幕最新精品| 国产一区二区三区丝袜| 精品久久久久国产| 亚洲一区亚洲二区亚洲三区| 中文字幕亚洲第一| 久久久久久这里只有精品| 欧美一区二区视频97| 成人精品一区二区三区电影免费| 精品亚洲永久免费精品| 曰本色欧美视频在线| 亚洲精品之草原avav久久| 中文字幕在线观看日韩| 最新69国产成人精品视频免费| 亚洲欧美日韩综合| 78m国产成人精品视频| 97色在线观看免费视频| 国产精品天天狠天天看| 亚洲最大福利视频网站| 久久露脸国产精品| 午夜精品一区二区三区视频免费看| 亚洲欧美国产视频| 亚洲成**性毛茸茸| 亚洲欧洲av一区二区| 欧美大尺度在线观看| 亚洲福利视频专区| 成人免费观看网址| 最近2019中文字幕第三页视频| 欧美国产日韩一区二区在线观看| 正在播放欧美一区| 欧美大尺度在线观看| 欧美一区二区三区艳史| 日本国产一区二区三区| 中文字幕在线看视频国产欧美| 成人黄色免费片| 国产精品网址在线| 国产自摸综合网| 97在线免费观看| 伊是香蕉大人久久| 国产精品扒开腿爽爽爽视频| 97精品国产97久久久久久| **欧美日韩vr在线| 国产色综合天天综合网| 成人乱人伦精品视频在线观看| 日韩免费黄色av| 成年人精品视频| 青草成人免费视频| 日韩av在线播放资源| 久久噜噜噜精品国产亚洲综合| 播播国产欧美激情| 亚洲视频在线观看网站| 久久视频在线播放| 久久久久久久国产精品视频| 中文字幕日韩免费视频| 2020欧美日韩在线视频| 亚洲精品小视频在线观看| 欧美成人精品h版在线观看| 国产在线高清精品| 欧美—级高清免费播放| 日韩av片电影专区| 国产精品久久国产精品99gif| 神马国产精品影院av| 色偷偷综合社区| 色综合天天综合网国产成人网| 午夜精品三级视频福利| 欧美日韩成人精品| 日韩中文字幕视频在线观看| 成人美女av在线直播| 成人免费观看49www在线观看| 国产va免费精品高清在线| 欧美极品少妇全裸体| 91大神福利视频在线| 欧美日韩在线视频一区| 亚洲在线免费观看| 国产精品一区二区3区| 久久视频国产精品免费视频在线| 成人97在线观看视频| 国产在线视频不卡| 久久男人资源视频| 久久在精品线影院精品国产| 国产成人亚洲综合91| 国产日韩欧美自拍| 91免费国产网站| 美乳少妇欧美精品| 精品国内亚洲在观看18黄| 夜夜嗨av色综合久久久综合网| 永久555www成人免费| 日本一区二区在线免费播放| 国产日韩在线看片| 精品久久久在线观看| 亚洲黄色www网站| 91精品在线国产| 美女精品视频一区| 国产成人avxxxxx在线看| 日韩中文在线中文网在线观看| 欧美最猛黑人xxxx黑人猛叫黄| 最近中文字幕mv在线一区二区三区四区| 成人av番号网| 国产成人精彩在线视频九色| 国产精品视频1区| 亚洲最大成人免费视频| 成人免费在线视频网站| 成人欧美一区二区三区黑人|