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

An idea plug-in that automatically generates unit tests, which improves the development efficiency by more than 70%!

Yann Lecun's new paper: the road to building automatic agents

Interface automation framework scaffolding - Implementation of parametric tools

港伦敦金行情走势图所隐藏的信息

Threads and thread pools

Set up your own website (11)

爱可可AI前沿推介(6.28)

Oracle 日期格式化异常:无效数字

DataEase安装升级

JS foundation 1-js introduction and operator
随机推荐
MySQL(二)
Debug debugging in katalon
Hystrix deployment
Markdown -- basic usage syntax
Metersphere uses JS to refresh the current page
Dataease installation upgrade
Realization of a springboard machine
Spatial-Temporal时间序列预测建模方法汇总
【功能建议】多个工作空间启动时选择某个空间
Metersphere实现UI自动化元素不可点击(部分遮挡)
What is the function of ICMP Protocol and the principle of Ping of death attack?
【SemiDrive源码分析】【X9芯片启动流程】32 - DisPlay模块分析 - RTOS侧
毕业季,给初入社会的你一些建议
Does flink1.15 support MySQL views? I configured the view name at the table name to save, but the table could not be found. Think
Datetime and logging module
Hystrix 部署
Ribbon core source code analysis
Katalon当中的使用循环for、while和if...else、break、continue
JS foundation 5
如何利用k线图做技术分析