当前位置:网站首页>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 ~
边栏推荐
猜你喜欢

Ruoyi integrated building block report (NICE)

fastposter v2.8.4 发布 电商海报生成器

Installing MySQL database (CentOS) in Linux source code

Mysql通用二进制安装方式

移动命令

Realize an air conditioner with compose to bring you cool in summer

线程和线程池

DlhSoft Kanban Library for WPF

How does ETF position affect spot gold price?

Katalon framework tests web (XX) custom keywords and upload pop-up operations
随机推荐
Blackmail virus of industrial control security
Yann LeCun新论文:构建自动智能体之路
Interface automation framework scaffolding - Implementation of parametric tools
Bytecode proof in appliedzkp zkevm (9)
Pop up and push in sequence of stack < difficulty coefficient >
JS基础10
MySQL (I)
【功能建议】多个工作空间启动时选择某个空间
MySQL (II)
[QT] connect syntax reference implementation
Knowing the details of redis RDB, you can step on many holes less
appliedzkp zkevm(10)中的Transactions Proof
Metersphere uses JS to refresh the current page
乌国家安全与国防委员会秘书:将对俄境内目标进行精确打击
Set up your own website (11)
Ribbon核心源码解析
一种跳板机的实现思路
JS foundation 5
Realize an air conditioner with compose to bring you cool in summer
What is the function of ICMP Protocol and the principle of Ping of death attack?