当前位置:网站首页>[depth first search] Ji Suan Ke: Betsy's trip
[depth first search] Ji Suan Ke: Betsy's trip
2022-07-06 01:57:00 【muse_ age】

DFS: Start to finish , If you happen to leave at the end n*n Step ,ans++;
If you don't prune , Will timeout
prune :
1、 Avoid walking into a dead end
2、 Avoid forming isolated areas

Code :
#include<iostream>
using namespace std;
int n;
int ans=0;
bool vis[8][8];
void dfs(int x,int y,int step){
if(!(x>=0&&y>=0&&x<n&&y<n))return;
if(vis[x][y]==true)return;
if(x==n-1&&y==0){
if(step==n*n-1){
ans++;
}
return;
}
if(x==n-1&&vis[x][y+1]==false&&vis[x][y-1]==false&&y-1>=0&&y+1<n||y==n-1&&vis[x+1][y]==false&&vis[x-1][y]==false&&x-1>=0&&x+1<n){
return;
}
vis[x][y]=true;
dfs(x+1,y,step+1);
dfs(x-1,y,step+1);
dfs(x,y+1,step+1);
dfs(x,y-1,step+1);
vis[x][y]=false;
}
int main(){
cin>>n;
dfs(0,0,0);
cout<<ans;
} Experience : Narrow the scope of , Use it well for debugging
边栏推荐
- NumPy 数组索引 切片
- 抓包整理外篇——————状态栏[ 四]
- Leetcode skimming questions_ Verify palindrome string II
- Code review concerns
- XSS learning XSS lab problem solution
- Basic operations of databases and tables ----- unique constraints
- How does the crystal oscillator vibrate?
- Regular expressions: examples (1)
- Redis string type
- 晶振是如何起振的?
猜你喜欢

Redis list

Cookie concept, basic use, principle, details and Chinese transmission
![Grabbing and sorting out external articles -- status bar [4]](/img/1e/2d44f36339ac796618cd571aca5556.png)
Grabbing and sorting out external articles -- status bar [4]

TrueType字体文件提取关键信息

PHP campus movie website system for computer graduation design

干货!通过软硬件协同设计加速稀疏神经网络
![[solved] how to generate a beautiful static document description page](/img/c1/6ad935c1906208d81facb16390448e.png)
[solved] how to generate a beautiful static document description page

Selenium waiting mode

02.Go语言开发环境配置

Poj2315 football games
随机推荐
【SSRF-01】服务器端请求伪造漏洞原理及利用实例
Leetcode3. Implement strstr()
ClickOnce does not support request execution level 'requireAdministrator'
leetcode-2. Palindrome judgment
A basic lintcode MySQL database problem
Computer graduation design PHP campus restaurant online ordering system
晶振是如何起振的?
Paddle framework: paddlenlp overview [propeller natural language processing development library]
Visualstudio2019 compilation configuration lastools-v2.0.0 under win10 system
leetcode-两数之和
Campus second-hand transaction based on wechat applet
Shutter doctor: Xcode installation is incomplete
UE4 unreal engine, editor basic application, usage skills (IV)
Redis list
Cadre du Paddle: aperçu du paddlelnp [bibliothèque de développement pour le traitement du langage naturel des rames volantes]
Computer graduation design PHP animation information website
genius-storage使用文档,一个浏览器缓存工具
Apicloud openframe realizes the transfer and return of parameters to the previous page - basic improvement
Basic operations of database and table ----- delete data table
Publish your own toolkit notes using NPM