当前位置:网站首页>【 planification dynamique】 différentes voies 2
【 planification dynamique】 différentes voies 2
2022-04-23 07:16:00 【Petit vent】
Liens https://leetcode-cn.com/problems/unique-paths-ii
Un robot dans un m x n Coin supérieur gauche de la grille,Le robot ne peut se déplacer qu'un pas vers le bas ou vers la droite à la fois.Le robot essaie d'atteindre le coin inférieur droit de la grille,Considérez maintenant les obstacles dans la grille.Combien de chemins différents vont suivre du coin supérieur gauche au coin inférieur droit?
Définition: d p [ i ] [ j ] dp[i][j] dp[i][j]Indique le numéro d'index ( 0 , 0 ) (0,0) (0,0)Au numéro d'index ( i , j ) (i,j) (i,j)Le nombre de trajets
Frontière:Première ligne et première colonne, d p [ 0 ] [ 0 ] dp[0][0] dp[0][0]Ça ne peut être que ça.1.En même temps,Comme vous ne pouvez marcher qu'en bas ou à droite,La première ligne et la première colonne sont donc directement calculables,Pour1,Si vous rencontrez un obstacle,Pour0.
Équation de transfert d'état: d p [ i ] [ j ] = { d p [ i − 1 ] [ j ] + d p [ i ] [ j − 1 ] , o b s t a c l e G r i d [ i ] [ j ] = 0 0 , o b s t a c l e G r i d [ i ] [ j ] ≠ 0 d p[i][j]= \begin{cases}d p[i-1][j]+dp[i][j-1], & obstacleGrid[i][j]~=\operatorname 0 \\ 0, & obstacleGrid[i][j]~≠\operatorname 0\end{cases} dp[i][j]={ dp[i−1][j]+dp[i][j−1],0,obstacleGrid[i][j] =0obstacleGrid[i][j] =0
Description:Valeur actuelle, égal à la somme de la ligne précédente et de la colonne de gauche ,Si vous rencontrez un obstacle,Pour0
class Solution:
def uniquePathsWithObstacles(self, obstacleGrid):
m = len(obstacleGrid)
n = len(obstacleGrid[0])
dp = [[0 for i in range(n)] for j in range(m)]
for i in range(n):
if obstacleGrid[0][i]==1:
break
dp[0][i] = 1
for i in range(m):
if obstacleGrid[i][0]==1:
break
dp[i][0] = 1
for i in range(1, m):
for j in range(1, n):
if obstacleGrid[i][j] == 0:
dp[i][j] = dp[i - 1][j] + dp[i][j - 1]
return dp[m-1][n-1]
版权声明
本文为[Petit vent]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230610323542.html
边栏推荐
- Bottomsheetdialogfragment conflicts with listview recyclerview Scrollview sliding
- adb shell 常用命令
- GEE配置本地开发环境
- iTOP4412 FramebufferNativeWindow(4.0.3_r1)
- org. xml. sax. SAXParseException; lineNumber: 141; columnNumber: 252; cvc-complex-type. 2.4. a: Found element 'B
- iTOP4412内核反复重启
- 【2021年新书推荐】Enterprise Application Development with C# 9 and .NET 5
- 杂七杂八的学习
- MySQL notes 3_ Restraint_ Primary key constraint
- Ffmpeg common commands
猜你喜欢

Explore how @ modelandview can forward data and pages through the source code

C#新大陆物联网云平台的连接(简易理解版)

红外传感器控制开关

C connection of new world Internet of things cloud platform (simple understanding version)
![[2021 book recommendation] kubernetes in production best practices](/img/78/2b5bf03adad5da9a109ea5d4e56b18.png)
[2021 book recommendation] kubernetes in production best practices

iTOP4412 HDMI显示(4.0.3_r1)
![[recommendation for new books in 2021] professional azure SQL managed database administration](/img/f1/b38cce1dc328a5b534011169909127.png)
[recommendation for new books in 2021] professional azure SQL managed database administration

杂七杂八的学习

Miscellaneous learning

Cancel remote dependency and use local dependency
随机推荐
机器学习 二:基于鸢尾花(iris)数据集的逻辑回归分类
图像分类白盒对抗攻击技术总结
this.getOptions is not a function
PyTorch最佳实践和代码编写风格指南
Kotlin征途之data class [数据类]
[recommendation of new books in 2021] enterprise application development with C 9 and NET 5
C connection of new world Internet of things cloud platform (simple understanding version)
adb shell常用模拟按键keycode
MySQL笔记2_数据表
取消远程依赖,用本地依赖
winform滚动条美化
Reading notes - activity
5种方法获取Torch网络模型参数量计算量等信息
Itop4412 cannot display boot animation (4.0.3_r1)
Android room database quick start
iTOP4412 FramebufferNativeWindow(4.0.3_r1)
Markdown basic grammar notes
【2021年新书推荐】Artificial Intelligence for IoT Cookbook
PyTorch中的一些常见数据类型转换方法,与list和np.ndarray的转换方法
iTOP4412 FramebufferNativeWindow(4.0.3_r1)