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

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

hdu1045【dfs】

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

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成人免费观看网站| 国产精品入口福利| 日韩专区在线观看| 欧美激情一区二区三区高清视频| 久久久久久久久久av| 国产美女被下药99| 91精品国产综合久久男男| 亚洲精品午夜精品| 欧美精品成人91久久久久久久| 欧美成人亚洲成人| 欧美第一淫aaasss性| 91网站在线免费观看| 国产成人精品综合| 欧美性生交大片免费| 国产精品高潮呻吟久久av黑人| 国产精品视频免费在线| 亚洲成avwww人| 国产黑人绿帽在线第一区| 日韩欧美亚洲综合| 成人a视频在线观看| 国产精品自拍偷拍视频| 精品久久久一区二区| 久久躁狠狠躁夜夜爽| 日韩精品极品在线观看播放免费视频| 成人妇女免费播放久久久| 在线观看久久久久久| 日韩欧美中文第一页| 秋霞成人午夜鲁丝一区二区三区| 国产亚洲欧洲高清一区| 久久久在线免费观看| 日韩美女激情视频| 久久久亚洲网站| 亚洲91精品在线观看| 亚洲天堂成人在线| 97欧美精品一区二区三区| 26uuu另类亚洲欧美日本老年| 精品久久久久久久久中文字幕| 91精品啪在线观看麻豆免费| 久久国产精品久久久久久久久久| 日韩成人在线电影网| 久久免费高清视频| 亚洲精品99久久久久中文字幕| 欧美成人免费全部| 日本亚洲欧美成人| 亚洲毛片在线观看.| 欧美电影在线观看网站| 国产999精品视频| 亚洲欧美国产高清va在线播| 久久国产精品亚洲| 不卡在线观看电视剧完整版| 欧美精品在线视频观看| 日韩国产欧美精品一区二区三区| 国产亚洲欧洲在线| 国产精品第8页| 91久久国产综合久久91精品网站| 国产亚洲精品va在线观看| 国产精品揄拍一区二区| 亚洲免费视频观看| 色青青草原桃花久久综合| 成人激情视频在线观看| 国产精品亚发布| 国产精品ⅴa在线观看h| 亚洲精品久久久久中文字幕欢迎你| 亚洲精品网站在线播放gif| 精品视频在线观看日韩| 日韩视频精品在线| 日韩精品高清在线观看| 久久久999精品视频| 国产v综合v亚洲欧美久久| 久久久久久国产精品久久| 亚洲精品网址在线观看| 精品色蜜蜜精品视频在线观看| 欧美成人激情图片网| 国产精品亚洲精品| 国产精品视频26uuu| 久久99精品国产99久久6尤物| 性金发美女69hd大尺寸| 日本久久久久久| 欧美精品999| 久久这里只有精品视频首页| 亚洲精品电影网站| 国产一区二区在线免费视频| 欧美一二三视频| 在线中文字幕日韩| 精品国产一区二区三区在线观看| 欧美精品国产精品日韩精品| 亚洲最大在线视频| 日本成熟性欧美| 国产免费一区二区三区在线能观看| 一区二区欧美亚洲| 欧美—级高清免费播放| 欧美性videos高清精品| 日本精品一区二区三区在线| 91免费看片网站| 国产偷亚洲偷欧美偷精品| 国内自拍欧美激情| 亚洲国产精久久久久久| 久久网福利资源网站| 日韩欧美国产成人| 亚洲国模精品一区| 欧美日韩一区免费| 亚洲成av人影院在线观看| 欧美激情三级免费| 欧美亚洲视频在线观看| 欧美在线视频一区| 精品国产鲁一鲁一区二区张丽| 欧美日韩国产丝袜美女| 九九久久综合网站| 欧美日韩国产综合新一区| 高清欧美电影在线| 91免费欧美精品| 久久精品电影一区二区| 欧美极品少妇与黑人| 美女999久久久精品视频| 亚洲精品久久久一区二区三区| 在线观看国产精品日韩av| 欧美高清视频在线观看| 国产一区二区丝袜高跟鞋图片| 国产xxx69麻豆国语对白| 91av在线网站| 久久精品国产一区二区三区| 亚洲的天堂在线中文字幕| 2020国产精品视频| 欧美日韩福利视频| 亚洲人成五月天| 亚洲精品久久久久国产| 欧美久久精品一级黑人c片| 色综合色综合久久综合频道88| 欧美激情亚洲一区| 亚洲第一级黄色片| 全色精品综合影院| 91欧美精品午夜性色福利在线| 91亚洲va在线va天堂va国| 亚洲第一区第二区| 热久久美女精品天天吊色| 国产日韩欧美视频在线| 国产精品视频地址| 亚洲一级一级97网| 国产精品户外野外| 国产亚洲xxx| 日韩中文字幕免费视频| 色综合色综合久久综合频道88| 97香蕉超级碰碰久久免费软件| 国产精品入口免费视频一| 国产精品69久久| 国产视频久久久| 日本不卡免费高清视频| 一区二区三区回区在观看免费视频| 精品久久久视频| 精品国偷自产在线视频99| 欧美第一淫aaasss性| 精品久久久久久久久中文字幕| 国内精品久久久久影院优| 国产精品一区二区av影院萌芽| 日韩小视频网址| 中文字幕综合一区| 欧美黑人又粗大| 亚洲第一av网站| 91精品国产综合久久男男| 亚洲黄页网在线观看| 在线播放日韩av| 日韩经典第一页| 国产视频观看一区| 国产一区二区丝袜|