# Exhaustive Search

问all possible results.

针对每个位置生成对应dfs的input: dfs(input). input可包含地图, 在地图上的位置pos, 当前状态cur, visited, res list, 上个位置的值等. dfs: 1. check input(pos, cur)是否合法, 不合法返回 2. check 状态cur是否满足res条件, 满足加入res list 3. 用循环产生所有可能的下个pos, 递归调用dfs(pos + 1, new cur). 当新的pos可能等同老pos时, 引入 visited. 当input中包含pos是意味着dfs首次调用会访问pos的, 因此visited\[pos] = true要放在循环外; 否则visted\[new pos]放在循环内.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hao-fu-1.gitbook.io/oj/exhaustive-search.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
