当前位置:网站首页>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论文投稿流程
- It's hard to hear C language? Why don't you take a look at my article (7) input and output
- Data communication foundation - Ethernet port mirroring and link aggregation
- 动态菜单,自动对齐
- Online filing process
- Chapter 10 project stakeholder management
- LeetCode Algorithm 剑指 Offer II 027. 回文链表
- 上新了,华为云开天aPaaS
- 大厂面试必问:如何解决TCP可靠传输问题?8张图带你详细学习
- Data center basic network platform
猜你喜欢

Stop using it indiscriminately. This is the real difference between @validated and @valid!!!

Chapter 10 project stakeholder management

1. fully explain the basic principles of IPSec

【Mongodb】READ_ME_TO_RECOVER_YOUR_DATA,数据库被恶意删除

2022-06-16 工作记录--JS-判断字符串型数字有几位 + 判断数值型数字有几位 + 限制文本长度(最多展示n个字,超出...)

ACL (access control list) basic chapter - Super interesting learning network

See how sparksql supports enterprise level data warehouse

Leetcode: push domino (domino simulation)

Vulnhub Vegeta: 1

动态菜单,自动对齐
随机推荐
CDN principle
EPICS记录参考3 -- 所有记录都有的字段
Based on the codeless platform, users deeply participated in the construction, and digital data + Nanjing Fiberglass Institute jointly built a national smart laboratory solution
Dynamic memory management (1)
2022-06-10 工作记录--JS-获取到某一日期N天后的日期
[untitled]
结合源码剖析Oauth2分布式认证与授权的实现流程
Introduction to machine learning compilation course learning notes lesson 1 overview of machine learning compilation
Panorama of enterprise power in China SSD industry
New, Huawei cloud Kaitian apaas
[QT] QT event handling
Recommended movies: Northeast tiger, licorice pizza
【个人实验报告】
vulnhub Vegeta: 1
「ARM 架构」是一种怎样的处理器架构?
Learn more about redis' eight data types and application scenario analysis
vulnhub Vegeta: 1
ThreadLocal memory leak
Unable to use the bean introduced into the jar package
China solar window market trend report, technical dynamic innovation and market forecast