## 回溯法基本思想
#### 基本思想
回溯法(英語:backtracking),又稱為試探法,是一種選優搜索法,按選優條件向前搜索,以達到目標。回溯法采用試錯的思想,它嘗試分步的去解決一個問題。在分步解決問題的過程中,當它通過嘗試發現現有的分步答案不能得到有效的正確的解答的時候,它將取消上一步甚至是上幾步的計算,再通過其它的可能的分步解答再次嘗試尋找問題的答案。
題目示例:
~~~
Fire Net
Time Limit: 2 Seconds Memory Limit: 65536 KB
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.
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.
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
~~~
#### 算法設計:
1.嘗試在每個空白處,放置碉堡
2.每次選擇放置碉堡后,進行深度優先搜索,搜索所有可能的碉堡放置情況
3.通過所有的嘗試得出碉堡的最大放置數
- 我的筆記
- 服務器
- ubuntu svn 環境的搭建
- ubuntu Memcache 的配置
- ubuntu 密鑰登錄服務器
- centos 搭建服務器環境
- nginx+tomcat 集群搭建
- 餐廳運營來看如何構建高性能服務器
- VMware-Centos-網絡配置
- Ubuntu-PHP-Apache-Mysql-PhpMyadmin的搭建
- UbuntuApache配置日志
- linux獲取當前執行腳本的目錄
- Ubuntu svn的快速配置(原創)
- Https配置
- Mysql 不支持遠程連接解決方案
- ubuntu+apache+rewrite
- php Mcrypt 擴展
- 重啟Apache出現警告信息Could not reliably determine the server's fully qualified domain name,
- Mysql無法遠程連接
- 定時任務設置
- Linux中Cache內存占用過高解決辦法
- Ubuntu14-04安裝redis和php5-redis擴展
- php
- thinkphp3.2 一站多城市配置
- PHP 安全編程建議(轉)
- phpexcel導入時間處理
- Mysql按時,天,月,年統計數據
- PHP-支付寶-APP支付
- 百度爬蟲-獲取全國數據
- PHPEXCEL導入導出excel文件
- php-微信app支付后端設計
- Phpqrcode生成二維碼
- 圖片+文字水印
- 數據庫優化
- java
- Mybatis 二級緩存
- 微信
- 微信公眾號多域名授權
- 微信掃碼支付
- web
- 網站性能優化方案實施
- ionic環境搭建
- 登錄設計方案
- 設置dev元素的寬高比例
- 設計模式
- app
- 版本更新
- 微擎數據庫操作擴展
- select
- find
- delete
- update
- insert
- where
- order
- page
- group
- having
- limit
- fields
- debug
- bind
- join
- alias
- query
- 聚合函數
- count
- sum
- max
- min
- avg
- 事務管理
- 自增自減
- 算法設計
- ACM:入口的選擇------深度優先搜索
- java:N的N次方
- 最少攔截系統:貪心思想
- ACM:蠶寶寶:搜索
- ACM:n!的位數 :斯特林公式
- 神奇的異或
- 中國剩余定理
- 矩陣翻硬幣
- 回溯法
- ACM程序設計網站集錦
- 博弈論
- 多維空間上的搜索算法
- 算法學習筆記之一(排序)
- 算法學習筆記之二(堆排序)
- 算法學習筆記之三(快速排序)
- ACM俱樂部密碼
- 原創開源
- 個人感悟