当前位置:网站首页>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);
}
}
边栏推荐
- Beijiafu (p+f) R2000 modified radar IP
- 证件照处理
- China smallpox vaccine market trend report, technical innovation and market forecast
- High level application of SQL statements in MySQL database (II)
- In the multi network card environment, the service IP registered by Nacos is incorrect, resulting in inaccessible services
- See how sparksql supports enterprise data warehouse
- 环境配置 | VS2017配置OpenMesh源码和环境
- 剑指 Offer 13. 机器人的运动范围
- 开发规范~参数校验异常、异常返回提示切面
- find your present (2)
猜你喜欢

【Mongodb】READ_ ME_ TO_ RECOVER_ YOUR_ Data, the database is deleted maliciously

重磅!法大大上榜“专精特新”企业

Future development of education industry of e-commerce Express

Can AI chat robots replace manual customer service?

中国SSD行业企业势力全景图

Nuscenes -- remedies for missing image files or 0-size images encountered during dataset configuration

2022-06-16 work record --js- judge the number of digits in string type digits + judge the number of digits in numeric type digits + limit the text length (display n words at most, exceeding...)

京东618会议平板排行榜公布,新锐黑马品牌会参谋角逐前三名,向国货老大华为学习

2022-06-10 work record --js- obtain the date n days after a certain date

C#学习两年的增删改查和C#导入导出(去重)案例
随机推荐
Heavyweight! Fada is listed as a "specialized and new" enterprise
canvas 实现图片新增水印
【软件工程】期末重点
Parental delegation mechanism
Row and column differences in matrix construction of DX HLSL and GL glsl
Programmers become gods by digging holes in one year, carrying flags in five years and becoming gods in ten years
Future development of education industry of e-commerce Express
2022-06-10 工作记录--JS-获取到某一日期N天后的日期
vulnhub Vegeta: 1
使用Aggregated APIServer扩展你的kubernetes API
ThreadLocal local thread
Analyze the implementation process of oauth2 distributed authentication and authorization based on the source code
问题求解——嵌套列表
中国SSD行业企业势力全景图
Basic principles of spanning tree protocol
【ROS玩转Turtlesim小海龟】
win10或win11打印机无法打印
【Laravel系列7.9】测试
The core concept of JMM: happens before principle
JWT(Json Web Token)