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

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

hdu1045【dfs】

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

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色精品久久| 97av在线播放| 久久久久久久久中文字幕| 亚洲字幕一区二区| 国产在线观看精品一区二区三区| 亚洲精品中文字幕女同| 国产精品热视频| 亚洲天堂久久av| 国产在线拍偷自揄拍精品| 国外日韩电影在线观看| 国产91av在线| 亚洲free性xxxx护士hd| 插插插亚洲综合网| 欧美老女人在线视频| 日韩欧美精品网址| 久精品免费视频| 国产成+人+综合+亚洲欧美丁香花| 国产亚洲福利一区| 国产va免费精品高清在线观看| 日韩福利伦理影院免费| 最近的2019中文字幕免费一页| 中文字幕亚洲激情| 亚洲人成在线观看| www国产91| 国产精品久久久久久久美男| 久久精品电影网站| 亚洲欧美国产一本综合首页| 久久久久久久国产精品视频| 欧美日在线观看| 成人激情免费在线| 热re99久久精品国产66热| 亚洲福利在线观看| 7m第一福利500精品视频| 亚洲美女免费精品视频在线观看| 久久久精品中文字幕| 日本中文字幕成人| 美日韩精品免费观看视频| 欧美精品成人91久久久久久久| 欧美日韩国产区| 日韩精品中文在线观看| 在线电影欧美日韩一区二区私密| 亚洲三级av在线| 亚洲免费电影在线观看| 欧美一级高清免费播放| 国产精品久久久久久久久久久新郎| 日韩免费不卡av| 国产热re99久久6国产精品| 另类视频在线观看| 国产成人综合av| 亚洲国产福利在线| 欧美精品videos性欧美| 热草久综合在线| 日韩视频第一页| 欧美三级欧美成人高清www| 久久伊人免费视频| 欧美视频不卡中文| 欧美疯狂做受xxxx高潮| 超薄丝袜一区二区| 欧美亚洲成人精品| 日韩av有码在线| 国产精品永久免费在线| 国产精品亚洲视频在线观看| 欧美日韩xxxxx| 一区三区二区视频| 欧美性开放视频| 欧美成人精品在线观看| 日韩大陆欧美高清视频区| 久久久久久网站| 国产日韩精品在线观看| 欧美第一黄网免费网站| 精品美女国产在线| 91国产视频在线| 国产精品一区二区三区久久久| 精品国内亚洲在观看18黄| 国产一区二区成人| 国产精彩精品视频| 亚洲欧美中文日韩在线| 亚洲成色999久久网站| 黑人巨大精品欧美一区二区三区| 国产精品白嫩美女在线观看| 欧美巨大黑人极品精男| 亚洲精品自拍视频| 91精品国产高清久久久久久91| 精品亚洲一区二区| 91精品国产91久久久久久| 欧美大片在线影院| 亚洲日本成人网| 国产999视频| 欧美午夜丰满在线18影院| 91国在线精品国内播放| 日韩经典中文字幕在线观看| 最新69国产成人精品视频免费| 久久久国产一区| 国产一区二区三区免费视频| 亚洲午夜色婷婷在线| 欧美日韩一区二区在线| 亚洲第一精品自拍| 国产视频久久网| 91九色国产社区在线观看| 久久视频这里只有精品| 久久九九免费视频| 久久中文精品视频| 亚洲国产精品成人一区二区| 国产美女精品视频免费观看| 亚洲成色www8888| www.日韩欧美| 亚洲网站视频福利| 欧美国产日产韩国视频| 精品动漫一区二区三区| 国内外成人免费激情在线视频| 欧美性猛交xxxx黑人猛交| 在线视频中文亚洲| 97人人模人人爽人人喊中文字| 日韩av手机在线观看| 日韩视频免费观看| 91色琪琪电影亚洲精品久久| 在线视频一区二区| 97精品免费视频| 国产成人久久久精品一区| 亚洲一区二区三区乱码aⅴ| 久久久久这里只有精品| 日韩小视频在线观看| 日本精品中文字幕| 亚洲欧美精品伊人久久| 色婷婷久久一区二区| 91精品国产91久久久久| 国产欧美精品在线播放| 欧美在线观看www| 国产精品欧美亚洲777777| 国产视频精品一区二区三区| 国产精品福利在线| 97国产精品久久| 91九色国产视频| 日本欧美一级片| 久久久精品国产网站| 成人在线视频网站| 国产日韩欧美在线观看| 91高清视频免费观看| 97国产精品视频| 国产精选久久久久久| 国产精品第七影院| 一区二区三区四区精品| 亚洲一区二区久久久久久久| 久久99亚洲热视| 日本高清+成人网在线观看| 91爱爱小视频k| 日韩av成人在线观看| 欧美黑人一区二区三区| 日韩免费中文字幕| 国产亚洲激情视频在线| 精品久久久国产精品999| 97精品国产97久久久久久春色| 国产精品久在线观看| 精品久久久久久久久中文字幕| 668精品在线视频| 国产噜噜噜噜噜久久久久久久久| 亚洲电影免费观看高清完整版| 欧美成年人视频网站| 成人国产在线视频| 欧美成人免费一级人片100| 久久久黄色av| 久久久久成人网| 青青a在线精品免费观看| www.欧美三级电影.com|