当前位置:网站首页>[jzof] 13 motion range of robot
[jzof] 13 motion range of robot
2022-07-23 18:14:00 【Sighed, angry】

import java.util.*;
public class Solution {
public int movingCount(int threshold, int rows, int cols)
{
int[] visited = new int[rows*cols];
return movingHelper(threshold,rows,cols,0,0,visited);
}
public int movingHelper(int threshold, int rows,int cols,int row, int col, int[] visited){
int count =0;
if(canReach(threshold,rows,cols,row,col,visited)){
visited[row*cols+col]=1;
count = 1+movingHelper(threshold,rows,cols,row-1,col,visited)
+movingHelper(threshold,rows,cols,row+1,col,visited)
+movingHelper(threshold,rows,cols,row,col-1,visited)
+movingHelper(threshold,rows,cols,row,col+1,visited);
}
return count;
}
public boolean canReach(int threshold, int rows, int cols, int row, int col, int[] visited){
if(row>=0 && row<rows && col<cols && col>=0 && visited[row*cols+col]==0 && getDigitSum(row)+getDigitSum(col)<=threshold)
return true;
else
return false;
}
public int getDigitSum(int num){
int sum =0;
while(num!=0){
sum = sum+ (num%10);
num = num/10;
}
return sum;
}
}
边栏推荐
- 20220721 积分环节的时频域分析
- MySQL master-slave synchronization delay solution
- 字符串长度函数strlen()。。字符串函数头文件string.h「建议收藏」
- VIM notes
- 阿里 P7 到底是怎样的水平?
- Multithreaded programming
- rhcsa笔记五
- Server environment setup
- "Nowadays, more than 99.9% of the code is garbage!"
- Seal player IP and machine code and unlock the blocked tutorial
猜你喜欢

On Monday, I asked | what constraints will take effect in the comprehensive stage of vivado?

MySQL事务,从redo log、bin log、undo log说起...

Reinforcement learning -- Markov decision process MP MRP MDP

go中高并发下的锁是如何工作的(结合源码)

go中高并发下的通信方式:channel管道的底层原理

The loss of training and testing does not decline, and the accuracy is extremely low
![[216] go language standard library package name](/img/14/bd12be4204ed44e114b1311f08c9e3.jpg)
[216] go language standard library package name

变分法 (Calculus of Variations)

“如今,99.9% 以上的代码都是垃圾!”

Seal player IP and machine code and unlock the blocked tutorial
随机推荐
Page return update
Detailed explanation of JPS
Explication détaillée du principe de co - intégration en go
Analyze the CPU surge of an RFID tag system written by.Net
Data crawling and display of e-commerce platform based on scratch
MySQL六十六问,两万字+五十图详解含(答案解析)
JVM – 彻底理解打破双亲委派机制
Sentinel installation diagram
Use moment to get the date of the current day and the next day
阿里 P7 到底是怎样的水平?
MPU9250传感器
Solutions to sap Hana database backup failure
js:图片url转base64编码
Web page basic template
vb连接Access数据库自定义
Calculus of variations
Eric6 installation problem
What about the reason why GOM and GEE set up a black screen and the fact that individual equipment maps are not displayed?
Open source needs specialization
(11) STM32 - IO pin multiplexing and mapping