当前位置:网站首页>[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;
}
}
边栏推荐
- CSDN定制T恤等你来拿,《新程序员》福利来袭!
- awk从入门到入土(16)awk综合案例
- 数字信号处理实验(一)
- MySQL foundation and performance optimization
- 配置Gom引擎登錄器出現錯誤提示:沒有發現必備補丁文件!
- Une erreur s'est produite lors de la configuration du login du moteur Gom: aucun correctif requis n'a été trouvé!
- 强化学习---马尔可夫决策过程 MP MRP MDP
- Salary high voltage line
- (十一)STM32——IO引脚复用与映射
- Web page basic template
猜你喜欢

Sentinel installation diagram

go中的協程原理詳解

Machine learning (9) - Feature Engineering (3) (supplementary)

go中的协程原理详解

leetcode:剑指 Offer II 115. 重建序列【图论思维 + 入度考虑 + 拓扑排序】

Activity Registration: how to quickly start the open source tapdata live data platform on a zero basis?

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

Salary high voltage line

go语言中的内存对齐是如何优化程序效率的?

防控调整后暑期市场井喷,途家、木鸟、美团暑期活动测评
随机推荐
配置Gom引擎登录器出现错误提示:没有发现必备补丁文件!
Three barriers in the workplace: annual salary of 300000, 500000 and 1million
卡方分布、方差分析
PDO operation
Ali Er Mian: what is CAS?
数字安全巨头Entrust披露六月遭到勒索软件团伙攻击
“如今,99.9% 以上的代码都是垃圾!”
How does memory alignment in go optimize program efficiency?
Phpstrom shortcut key
js:图片url转base64编码
Why can Hong Kong servers be exempted from filing
MySQL 66 questions, 20000 words + 50 pictures, including (answer analysis)
数据库建模
微服务雪崩问题及解决方案
Seata
Data crawling and display of e-commerce platform based on scratch
Use moment to get the date of the current day and the next day
aspose的仓库地址
go中的协程原理详解
Non inherited polymorphic ideas cooperate with typeID to realize the transmission of different parameters