当前位置:网站首页>[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
边栏推荐
- 抓包整理外篇——————状态栏[ 四]
- Leetcode skimming questions_ Invert vowels in a string
- [Jiudu OJ 09] two points to find student information
- 3D视觉——4.手势识别(Gesture Recognition)入门——使用MediaPipe含单帧(Singel Frame)和实时视频(Real-Time Video)
- Redis-字符串类型
- 同一个 SqlSession 中执行两条一模一样的SQL语句查询得到的 total 数量不一样
- Card 4G industrial router charging pile intelligent cabinet private network video monitoring 4G to Ethernet to WiFi wired network speed test software and hardware customization
- Flowable source code comments (36) process instance migration status job processor, BPMN history cleanup job processor, external worker task completion job processor
- Flutter Doctor:Xcode 安装不完整
- module ‘tensorflow. contrib. data‘ has no attribute ‘dataset
猜你喜欢
Redis-字符串类型
Initialize MySQL database when docker container starts
【已解决】如何生成漂亮的静态文档说明页
[flask] official tutorial -part2: Blueprint - view, template, static file
2022年PMP项目管理考试敏捷知识点(8)
Leetcode3. Implement strstr()
Blue Bridge Cup embedded_ STM32_ New project file_ Explain in detail
Unity learning notes -- 2D one-way platform production method
Card 4G industrial router charging pile intelligent cabinet private network video monitoring 4G to Ethernet to WiFi wired network speed test software and hardware customization
Basic operations of databases and tables ----- default constraints
随机推荐
【Flask】静态文件与模板渲染
Bidding promotion process
leetcode-2.回文判断
Apicloud openframe realizes the transfer and return of parameters to the previous page - basic improvement
【全网最全】 |MySQL EXPLAIN 完全解读
3D vision - 4 Getting started with gesture recognition - using mediapipe includes single frame and real time video
Tensorflow customize the whole training process
【详细】快速实现对象映射的几种方式
Selenium element positioning (2)
How to upgrade kubernetes in place
Unreal browser plug-in
Basic operations of databases and tables ----- non empty constraints
Selenium waiting mode
01.Go语言介绍
Alibaba canal usage details (pit draining version)_ MySQL and ES data synchronization
PHP error what is an error?
NumPy 数组索引 切片
Basic operations of database and table ----- delete data table
抓包整理外篇——————状态栏[ 四]
[solved] how to generate a beautiful static document description page