当前位置:网站首页>[dynamic planning] path dp:931 Minimum Falling Path Sum
[dynamic planning] path dp:931 Minimum Falling Path Sum
2022-07-01 01:30:00 【Twilight_ years】
Given an n x n array of integers matrix, return the minimum sum of any falling path through matrix.
A falling path starts at any element in the first row and chooses the element in the next row that is either directly below or diagonally left/right. Specifically, the next element from position (row, col) will be (row + 1, col - 1), (row + 1, col), or (row + 1, col + 1).
Go down from the first line , You can walk three places at a time , Go to the last line , Find the minimum path sum
Pay attention to initialization :
dp[i][j]=INF
dp Subscript to be 1 Express g[0],dp[0][j]=0( Avoid boundary discussions )
class Solution {
public int minFallingPathSum(int[][] g) {
int n=g.length;
int [][] dp=new int[n+2][n+2];
for(int i=0;i<=n+1;i++)
Arrays.fill(dp[i],0x3f3f3f3f);
for(int i=0;i<=n+1;i++){
dp[0][i]=0;
}
int res=0x3f3f3f3f;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
dp[i][j]=Math.min(dp[i][j],Math.min(dp[i-1][j],Math.min(dp[i-1][j-1],dp[i-1][j+1]))+g[i-1][j-1]);
if(i==n){
res=Math.min(res,dp[i][j]);
}
}
}
return res;
}
}
边栏推荐
- Solve idea:class' xxx 'not found in module' xxx‘
- StrictMode卡顿与泄漏检测-StrictMode原理(2)
- Dx-11q signal relay
- None of the following candidates is applicable because of a receiver type mismatch
- Parity linked list [two general directions of linked list operation]
- 自定义注解实现校验
- 用Steam教育启发学生多元化思维
- Basic knowledge II - Basic definitions related to sta
- 元宇宙为 VR/AR 带来的新机会
- TypeError: can‘t convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to
猜你喜欢

日志 logrus第三方库的使用

用recyclerReview展示Banner,很简单
![[learning notes] double + two points](/img/d4/1ef449e3ef326a91966da11b3c8210.png)
[learning notes] double + two points
![[问题已处理]-nvidia-smi命令获取不到自身容器的GPU进程和外部的GPU进程号](/img/51/e48e222c14f4a4e9f2be91a677033f.png)
[问题已处理]-nvidia-smi命令获取不到自身容器的GPU进程和外部的GPU进程号

Dls-20 double position relay 220VDC

Windows环境下安装MongoDB数据库

6月第4周榜单丨飞瓜数据UP主成长排行榜(哔哩哔哩平台)发布!

图的连通性基础

Install redis database and download redis Desktop Manager in win11
![[learning notes] structure](/img/55/9623ba97f57eff71c246684e3a2bba.png)
[learning notes] structure
随机推荐
微生物安全与健康,什么是生物处理?
Typora的使用
Strictmode analysis activity leakage -strictmode principle (3)
[learning notes] double + two points
Service grid ASM year end summary: how do end users use the service grid?
OCR的一些项目
【模拟】922. Sort Array By Parity II
微生物检测,土壤微生物的作用有哪些?
mysql数据库基础:流程控制
Poor students can also play raspberry pie
友盟(软件异常实时监听的好帮手:Crash)接入教程(有点基础的小白最易学的教程)
Principes de formation de la programmation robotique
Service grid ASM year end summary: how do end users use the service grid?
Why build a personal blog
Orb-slam2 source code learning (II) map initialization
Windows环境下安装MongoDB数据库
元宇宙为 VR/AR 带来的新机会
使用 C# 创造 ASCII 艺术
Parity linked list [two general directions of linked list operation]
Note d'étude du DC: zéro dans le chapitre officiel - - Aperçu et introduction du processus de base