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

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

hdu1045【dfs】

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

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
亚洲国产欧美自拍| 日韩精品视频在线| 国内精品伊人久久| 国产精品第二页| 欧美午夜视频在线观看| 91中文字幕在线观看| 亚洲在线视频福利| 国产视频亚洲精品| www.xxxx精品| 中文字幕无线精品亚洲乱码一区| xxx欧美精品| 热re91久久精品国99热蜜臀| 国产精选久久久久久| 91在线观看免费高清| 国产91色在线| 这里只有精品久久| 国产欧美亚洲视频| 欧美日韩国产在线播放| 日韩电影在线观看免费| 国产精品大片wwwwww| 秋霞成人午夜鲁丝一区二区三区| 在线观看欧美日韩国产| 久久精品影视伊人网| 日韩福利视频在线观看| 欧美日韩国产专区| 国产欧美精品在线| 欧美日韩国产限制| 亚洲一区二区三区毛片| 国产综合香蕉五月婷在线| 亚洲白拍色综合图区| 亚洲国产又黄又爽女人高潮的| 一区二区三区精品99久久| 欧美精品少妇videofree| 97视频在线观看网址| 97色在线观看| 亚洲性夜色噜噜噜7777| 亚洲精品影视在线观看| 精品毛片三在线观看| 亚洲精品福利在线| 久久久av免费| 亚洲人成绝费网站色www| 中文字幕亚洲无线码a| 国产午夜精品麻豆| 中文字幕亚洲欧美日韩高清| 国产精品视频公开费视频| 欧美伊久线香蕉线新在线| 午夜精品理论片| 国产999精品久久久影片官网| 91久久夜色精品国产网站| 97在线观看免费高清| 久久国产天堂福利天堂| 国产日韩欧美电影在线观看| 欧美专区中文字幕| 午夜精品久久久久久久久久久久| 色婷婷av一区二区三区久久| 日本aⅴ大伊香蕉精品视频| 国产精品色视频| 精品视频一区在线视频| 国内成人精品视频| 最新国产成人av网站网址麻豆| 亚洲影影院av| 性欧美长视频免费观看不卡| 日韩在线观看网址| 2019精品视频| 性欧美激情精品| 成人h视频在线观看播放| 亚洲欧美激情视频| 亚洲无限乱码一二三四麻| 欧美日韩亚洲一区二区三区| 亚洲免费一在线| 亚洲激情中文字幕| 97欧美精品一区二区三区| 久久久女人电视剧免费播放下载| 久久久久久网址| 中文字幕av一区二区三区谷原希美| 亚州精品天堂中文字幕| 亚洲xxx自由成熟| 欧美激情免费看| 欧美国产精品人人做人人爱| 91精品国产高清自在线看超| 欧美高清性猛交| 成人黄色在线观看| 九九热精品视频在线播放| 色偷偷av一区二区三区乱| 欧美另类99xxxxx| 欧美激情videoshd| 国产aaa精品| 亚洲另类图片色| 91精品国产91久久久久久| 国产精品国产自产拍高清av水多| 日韩福利视频在线观看| 成人精品视频久久久久| 欧美精品www| 欧美日本高清一区| 97精品视频在线| 亚洲精品中文字幕女同| 中文字幕免费精品一区高清| 日韩精品极品视频免费观看| 亚洲黄色有码视频| 欧美xxxx综合视频| 欧美野外wwwxxx| 国产欧美日韩精品丝袜高跟鞋| 国产亚洲福利一区| 成人免费观看网址| 97激碰免费视频| 国产精品久久久久久久久粉嫩av| 精品久久香蕉国产线看观看gif| 高清欧美一区二区三区| 国产日韩在线观看av| 在线观看国产成人av片| 久久精品国产免费观看| 国产在线精品一区免费香蕉| 午夜精品一区二区三区av| 欧洲美女免费图片一区| 欧美日韩在线第一页| 亚洲精品一区久久久久久| 欧美精品久久久久久久免费观看| 日韩欧美999| 日韩美女av在线| 97视频在线免费观看| 一区二区成人精品| 久久久久久久一区二区三区| 亚洲va码欧洲m码| 国产日韩欧美另类| 国产成人涩涩涩视频在线观看| 国产精品永久免费视频| 精品电影在线观看| 欧美成人免费va影院高清| 26uuu另类亚洲欧美日本一| 91视频免费网站| 欧美亚洲视频在线看网址| 亚洲va国产va天堂va久久| 欧美一级淫片丝袜脚交| 欧美视频裸体精品| 国产精品久久久久久久一区探花| 欧美wwwxxxx| 成人午夜一级二级三级| 国产精品美女www爽爽爽视频| 国产精品久久在线观看| 亚洲自拍在线观看| 亚洲欧美在线播放| 国产日韩精品综合网站| 国产成人综合精品在线| 亚洲第一网站免费视频| 久久久天堂国产精品女人| 久久人人爽人人爽人人片av高清| 午夜精品一区二区三区在线视频| 精品国产乱码久久久久久天美| 亚洲一区二区三区久久| 亚洲国产91精品在线观看| 美女扒开尿口让男人操亚洲视频网站| 91久久久亚洲精品| 国产v综合ⅴ日韩v欧美大片| 国产国语videosex另类| 久久视频精品在线| 久久全球大尺度高清视频| 精品国产31久久久久久| 国产精品18久久久久久麻辣| 欧美噜噜久久久xxx| 亚洲电影免费观看| 亚洲欧美成人精品| 欧美国产日韩视频| 8x拔播拔播x8国产精品| 国产日韩欧美91|