当前位置:网站首页>Blue Bridge Cup Maze (dfs+ backtracking)
Blue Bridge Cup Maze (dfs+ backtracking)
2022-06-28 10:55:00 【Woodenman Du】
Question:

Solve:
Try every point violently , See if you can go out of bounds according to the path on the question .
The last three words are worth noting , Go around in circles , This also means that each grid must be marked to prevent infinite recursion .
And don't forget that the ordinate is x Elements , Abscissa is y Elements
Code:
#include <bits/stdc++.h>
using namespace std;
string a[11] = {"...........",
".UDDLUULRUL",
".UURLLLRRRU",
".RRUURLDLRD",
".RUDDDDUUUU",
".URUDLLRRUU",
".DURLRLDLRL",
".ULLURLLRDU",
".RDLULLRDDD",
".UUDDUDUDLL",
".ULRDLUURRR"
};
int res = 0;
bool judge[11][11];
void dfs(int x, int y)
{
// Out of the border , Add one to the result
if(x <= 0 || x > 10 || y <= 0 || y > 10 ) { res++; return; }
// The point we went through , return
if(judge[x][y]) return;
// Continue to go
if(a[x][y] == 'L') { judge[x][y] = true; dfs(x,y-1); judge[x][y] = false; }
else if(a[x][y] == 'R') { judge[x][y] = true; dfs(x,y+1); judge[x][y] = false; }
else if(a[x][y] == 'U') { judge[x][y] = true; dfs(x-1,y); judge[x][y] = false; }
else if(a[x][y] == 'D') { judge[x][y] = true; dfs(x+1,y); judge[x][y] = false; }
}
int main(void)
{
memset(judge,false,sizeof(judge));
for(int i = 1; i <= 10; i++)
for(int j = 1; j <= 10; j++)
dfs(i,j);
cout <<res;
return 0;
}Statement : The pictures are from the official website of the Blue Bridge Cup , For the purpose of sorting out personal questions , In case of infringement , Please contact to delete ~
边栏推荐
猜你喜欢
随机推荐
datetime与logging模块
JS基础3
Compression and decompression
Knowing the details of redis RDB, you can step on many holes less
MySQL (I)
vsftpd服务的部署及优化
Hystrix 部署
一款自动生成单元测试的 IDEA 插件,开发效率提升 70% 以上!
Katalon框架测试web(二十)自定义关键字以及上传弹窗操作
appliedzkp zkevm(10)中的Transactions Proof
【SemiDrive源码分析】【X9芯片启动流程】32 - DisPlay模块分析 - RTOS侧
Using loops for, while, and if in katalon else、break、continue
字符串 & 堆 & 方法区
还在用 SimpleDateFormat 做时间格式化?小心项目崩掉!
阿里三面:LEFT JOIN关联表中用ON还是WHERE跟条件有什么区别
What is the function of ICMP Protocol and the principle of Ping of death attack?
An idea plug-in that automatically generates unit tests, which improves the development efficiency by more than 70%!
Fastposter v2.8.4 release e-commerce poster generator
Debug debugging in katalon
JS foundation 5







