当前位置:网站首页>[daily algorithm 94] classic interview question: motion range of robot
[daily algorithm 94] classic interview question: motion range of robot
2022-07-27 09:00:00 【51CTO】
I've been busy interviewing recently , I didn't want to change today , But I'm too tired to read the basic knowledge , So I wrote a question to solve the pressure .
Topic link
LeetCode Interview questions 13. The range of motion of the robot [1]
Title Description
There is one on the ground m That's ok n Grid of columns , From coordinates [0, 0] To coordinates [m-1, n-1] . A robot from coordinates [0, 0] The grid starts to move , It can go left every time 、 Right 、 On 、 Move down one space ( Can't move out of the box ), The sum of the digits of row coordinates and column coordinates is greater than k Lattice of . for example , When k by 18 when , Robots can enter the grid [35, 37] , because 3+5+3+7=18. But it can't get into the grid [35, 38], because 3+5+3+8=19. How many squares can the robot reach ?
Example 1
Example 2
explain :
-
1 <= n,m <= 100 -
0 <= k <= 20
Answer key
There is no algorithm for this problem , Relatively simple , Mainly examine your code implementation ability , Here I write two methods , One BFS, One DFS.
BFS
BFS The idea is to use a queue to save the nodes to be accessed , And keep getting out of the team , Join the nodes around the current node that meet the requirements . In order to avoid repeated visits , You can use a vis Array to mark the node location that has been accessed .
DFS
DFS The idea is clearer and simpler , For a node , The total number of nodes that can be accessed from it is equal to the total number of nodes that can be accessed from the nodes around it plus one . You also need to use one vis Array to mark the node location that has been accessed .
Code
BFS(c++)
DFS(c++)
Reference material
[1]
LeetCode Interview questions 13. The range of motion of the robot : https://leetcode-cn.com/problems/ji-qi-ren-de-yun-dong-fan-wei-lcof/
边栏推荐
- 1.3.1 Full Permutation Problem
- 4279. 笛卡尔树
- NiO Summary - read and understand the whole NiO process
- How to upload dynamic GIF map in blog
- Flink1.15源码阅读flink-clients客户端执行流程(阅读较枯燥)
- 杭州电子商务研究院发布“数字化存在”新名词解释
- NIO总结文——一篇读懂NIO整个流程
- 500报错
- Pytorch custom CUDA operator tutorial and runtime analysis
- JS detects whether the client software is installed
猜你喜欢

软件测试功能测试全套常见面试题【功能测试-零基础】必备4-1

“鼓浪屿元宇宙”,能否成为中国文旅产业的“升级样本”

"Weilai Cup" 2022 Niuke summer multi school training camp 1

Activation functions commonly used in deep learning

Mangodb简单使用

PVT's spatial reduction attention (SRA)

网络IO总结文

The following license SolidWorks Standard cannot be obtained, and the use license file cannot be found. (-1,359,2)。

Five kinds of 2D attention finishing (non local, criss cross, Se, CBAM, dual attention)

Arm system call exception assembly
随机推荐
Software testing function testing a full set of common interview questions [function testing - zero foundation] essential 4-1
4279. Cartesian tree
Flask's operations on model classes
4278. Summit
Is it safe to buy funds every day? Online and other answers
How to study happily on station B?
Aruba学习笔记10-安全认证-Portal认证(web页面配置)
Solve the problem of Chinese garbled code on the jupyter console
Flink1.15源码阅读flink-clients客户端执行流程(阅读较枯燥)
[I2C reading mpu6050 of Renesas ra6m4 development board]
CUDA programming-04: CUDA memory model
pollFirst(),pollLast(),peekFirst(),peekLast()
03.使用引号来监听对象嵌套值的变化
Apple cut its price by 600 yuan, which was almost a devastating blow to the collapse of its domestic flagship mobile phone
NiO example
TensorFlow损失函数
3311. 最长算术
[interprocess communication IPC] - semaphore learning
4278. 峰会
5g failed to stimulate the development of the industry, which disappointed not only operators, but also mobile phone enterprises