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

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

hdu1045【dfs】

2019-11-10 20:05:10
字體:
來源:轉載
供稿:網友

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电影| 亚洲视频在线观看网站| 中文字幕日韩av综合精品| 欧美成在线视频| 国模私拍视频一区| 国产精品自产拍高潮在线观看| 久久国产精品首页| 国产一区二区三区高清在线观看| 成人午夜激情免费视频| 亚洲欧美日韩成人| 精品中文字幕视频| 日韩第一页在线| 国产精品一香蕉国产线看观看| 大伊人狠狠躁夜夜躁av一区| 久久视频在线观看免费| 色噜噜亚洲精品中文字幕| 亚洲精品国产欧美| 欧美日韩精品二区| 日韩av在线网址| 国产精品久久一区主播| 国产99久久精品一区二区永久免费| 久久露脸国产精品| 91在线观看免费| 国产精品精品久久久| 亚洲色图校园春色| 国产美女91呻吟求| 国产成人鲁鲁免费视频a| 日韩av在线高清| 国产精品极品在线| 亚洲综合中文字幕68页| 2025国产精品视频| 日韩av在线网页| 亚洲欧美www| 深夜福利91大全| 九九热99久久久国产盗摄| 国产91精品久久久久| 亚洲精品免费一区二区三区| 亚洲国语精品自产拍在线观看| 91精品国产乱码久久久久久蜜臀| 国产精品视频公开费视频| 夜夜嗨av色一区二区不卡| 久久在线精品视频| 日韩av电影国产| 色妞一区二区三区| 日韩免费av一区二区| 欧美与欧洲交xxxx免费观看| 亚洲第一福利视频| 国产精品中文字幕久久久| 亚洲精品福利免费在线观看| 亚洲福利影片在线| 色偷偷噜噜噜亚洲男人的天堂| 97热精品视频官网| 成人黄色中文字幕| 国产精品免费看久久久香蕉| 一本色道久久综合亚洲精品小说| 亚洲精品资源美女情侣酒店| 日韩欧美中文字幕在线播放| 国内精品久久久久久久| www.日韩.com| 在线成人免费网站| 日韩高清av一区二区三区| 久久伊人精品一区二区三区| 96精品视频在线| 中文字幕免费精品一区高清| 91探花福利精品国产自产在线| 亚洲欧美日韩国产精品| 中文字幕国产精品| 精品久久久久久久久久久久久| 色视频www在线播放国产成人| 久久久久久国产精品久久| 欧美专区国产专区| 国产欧美一区二区三区久久| www.xxxx欧美| 亚洲精品v天堂中文字幕| 国产精品久久久久99| 最近2019年日本中文免费字幕| 成人激情在线播放| 国产精品视频白浆免费视频| 日韩久久免费视频| 亚洲人免费视频| 亚洲综合在线做性| 一区二区国产精品视频| 国外成人免费在线播放| 亚洲视频欧洲视频| 俺去了亚洲欧美日韩| 不卡伊人av在线播放| 精品久久久久久久久中文字幕| 亚洲午夜av久久乱码| 欧美久久精品一级黑人c片| 欧美精品一区在线播放| 国产精品对白刺激| 中文字幕亚洲欧美日韩在线不卡| 97超碰蝌蚪网人人做人人爽| 精品福利樱桃av导航| 亚洲淫片在线视频| 国产深夜精品福利| 国产大片精品免费永久看nba| 久久精品电影一区二区| 久久久久久久97| 欧美电影电视剧在线观看| 日韩精品黄色网| 亚洲男人av电影| 欧美激情区在线播放| 中文国产亚洲喷潮| 国产精品女视频| 久久中文字幕国产| 国产午夜精品全部视频在线播放| 日韩在线一区二区三区免费视频| 欧美日韩在线第一页| 中文字幕九色91在线| 亚洲精品国精品久久99热一| 久久精品久久久久久| 啪一啪鲁一鲁2019在线视频| 欧美综合激情网| 国产精品自产拍高潮在线观看| 久久国产精品久久国产精品| 亚洲欧美中文字幕| 欧美巨大黑人极品精男| 欧美成人精品一区二区| 日韩一中文字幕| 欧美一区二区三区……| 亚洲男人天堂网| 91麻豆国产语对白在线观看| 色与欲影视天天看综合网| www欧美xxxx| 久久久成人的性感天堂| 日本亚洲欧洲色| 欧美中文在线字幕| 亚洲国产成人在线视频| 精品久久久香蕉免费精品视频| 日韩av片电影专区| 中文字幕av一区二区| 亚洲国产成人91精品| 国产精品极品美女在线观看免费| 中文字幕在线成人| 日韩美女写真福利在线观看| 国产精品九九九| 中文字幕亚洲专区| 久久久欧美一区二区| 欧美在线观看一区二区三区| 美女av一区二区三区| 欧美激情视频一区二区三区不卡| 久久久国产精品免费| 亚洲国产成人91精品| 欧美日韩国产成人高清视频| 欧美激情精品久久久久久变态| 欧美高清激情视频| 亚洲国产成人精品一区二区| 欧美裸身视频免费观看| 日韩在线观看网站| 亚洲伊人久久综合| 精品国产91久久久久久| 91tv亚洲精品香蕉国产一区7ujn| 国产精品一区二区性色av| 日韩av网站导航| 国产亚洲精品综合一区91| 91精品国产综合久久久久久久久| 91在线观看免费| 亚洲男人天天操| 欧美一区二区影院| 亚洲午夜精品久久久久久性色| 亚洲精品v天堂中文字幕| 国产欧美欧洲在线观看|