当前位置:网站首页>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);
}
}
边栏推荐
- [WSL] SSH Remote Connection and host port forwarding configuration
- LeetCode Algorithm 剑指 Offer II 027. 回文链表
- Online filing process
- cat写多行内容到文件
- 【WSL】SSH 远程连接及宿主机端口转发配置
- Data communication foundation - Ethernet port mirroring and link aggregation
- Power system | IEEE paper submission process
- 京东618会议平板排行榜公布,新锐黑马品牌会参谋角逐前三名,向国货老大华为学习
- Leetcode algorithm refers to offer II 027 Palindrome linked list
- Stop using it indiscriminately. This is the real difference between @validated and @valid!!!
猜你喜欢

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

Heavyweight! Fada is listed as a "specialized and new" enterprise

Servlet

「ARM 架构」是一种怎样的处理器架构?

nuScenes——数据集配置过程中遇到图像文件缺失或大小为0时的补救方法

【Laravel系列7.9】测试

环境配置 | VS2017配置OpenMesh源码和环境

High level application of SQL statements in MySQL database (I)

Combine pod identity in aks and secret in CSI driver mount key vault

Layer 2 and layer 3 forwarding principle based on VLAN
随机推荐
Chapter 10 project communication management
Leetcode: push domino (domino simulation)
2022年高压电工考试模拟100题及在线模拟考试
Talk about GC mechanism often asked in interview
开发规范~参数校验异常、异常返回提示切面
JMM 最最最核心的概念:Happens-before 原则
Feign project construction
ThreadLocal memory leak
中国SSD行业企业势力全景图
上新了,华为云开天aPaaS
【软件工程】期末重点
Layer 2 and layer 3 forwarding principle based on VLAN
Annotation
【Mongodb】READ_ME_TO_RECOVER_YOUR_DATA,数据库被恶意删除
Market trend report, technical innovation and market forecast of solar roof system in China
Idea close global search box
The usage difference between isempty and isblank is so different that so many people can't answer it
Solution to the login error of tangdou people
It's hard to hear C language? Why don't you take a look at my article (7) input and output
证件照处理