当前位置:网站首页>Sword finger offer 13 Range of motion of robot
Sword finger offer 13 Range of motion of robot
2022-06-24 22:55:00 【Who knows the big dream I】
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:
Input :m = 2, n = 3, k = 1
Output :3
Example 2:
Input :m = 3, n = 1, k = 0
Output :1
Tips :
1 <= n,m <= 100
0 <= k <= 20
class Solution {
int res=0;
public int movingCount(int m, int n, int k) {
boolean[][] arr = new boolean[m][n];// Used as a tag array
dfs(0,0,m,n,k,arr);
return res;
}
private void dfs(int i, int j, int m, int n,int k,boolean[][] arr) {
// Basic judgment + Judge whether to walk this road
if (i>=m||i<0||j>=n||j<0||arr[i][j]){
return;
}
//m No, I haven't . Mark... First , In judging whether it conforms to the meaning of the question
arr[i][j]=true;
// Sum up
int sum =i%10+j%10+i/10+j/10;
// Judge whether the conditions are met
if (sum>k) return;
res++;
// Direct large-scale casting
dfs(i+1,j,m,n,k,arr);
dfs(i-1,j,m,n,k,arr);
dfs(i,j+1,m,n,k,arr);
dfs(i,j-1,m,n,k,arr);
}
}
边栏推荐
- 电力系统| IEEE论文投稿流程
- 问题求解——嵌套列表
- Development specification - parameter verification exception, exception return prompt section
- Envoy obtain the real IP address of the client
- Tetris
- Online filing process
- Power system | IEEE paper submission process
- EPICS记录参考3 -- 所有记录都有的字段
- Basic principles of spanning tree protocol
- Dynamic memory management (1)
猜你喜欢

Development specification - parameter verification exception, exception return prompt section

The difference between interceptor and filter

The usage difference between isempty and isblank is so different that so many people can't answer it

vulnhub DC: 2

shopee开店入驻流水如何提交?

Database transaction Transanction

Introduction to machine learning compilation course learning notes lesson 1 overview of machine learning compilation

面试害怕被问MySQL相关问题 ?这份三万字精华总结 + 面试100 问,吊打面试官完全够了

Row and column differences in matrix construction of DX HLSL and GL glsl

2022年高处安装、维护、拆除考试模拟100题及模拟考试
随机推荐
Annotation
The difference between interceptor and filter
详细了解关于sentinel的实际应用
Selection and comparison of message oriented middleware MQ
VRRP skills topic
Dynamic memory management (1)
The usage difference between isempty and isblank is so different that so many people can't answer it
How to integrate Huawei cloud function services in fluent
环境配置 | VS2017配置OpenMesh源码和环境
EPICS记录参考3 -- 所有记录都有的字段
【軟件工程】期末重點
Panorama of enterprise power in China SSD industry
Code farmers should also understand the IPv4 subnet division of point networks
Solution to the login error of tangdou people
Data communication foundation - Ethernet port mirroring and link aggregation
Database transaction Transanction
MySQL夺命10问,你能坚持到第几问?
[WSL] SSH Remote Connection and host port forwarding configuration
Research Report on terahertz imaging system industry - market status analysis and development prospect forecast
Visitor tweets tell you which groups are consuming blind boxes