当前位置:网站首页>62. different paths - Dynamic Planning
62. different paths - Dynamic Planning
2022-06-10 10:23:00 【hequnwang10】
One 、 Title Description
A robot is in a m x n The top left corner of the grid ( The starting point is marked as “Start” ).
The robot can only move down or right one step at a time . The robot tries to reach the bottom right corner of the grid ( In the figure below, it is marked as “Finish” ).
Ask how many different paths there are in total ?
Example 1:

Input :m = 3, n = 7
Output :28
Example 2:
Input :m = 3, n = 2
Output :3
explain :
From the top left corner , All in all 3 Path to the bottom right .
1. towards the right -> Down -> Down
2. Down -> Down -> towards the right
3. Down -> towards the right -> Down
Example 3:
Input :m = 7, n = 3
Output :28
Example 4:
Input :m = 3, n = 3
Output :6
Two 、 Problem solving
Dynamic programming
How many paths in total : dp[i][j] = dp[i-1][j] + dp[i][j-1];
Expand : Shortest path : dp[i][j] = Math.max(dp[i-1][j],dp[i][j-1])+1;
class Solution {
public int uniquePaths(int m, int n) {
// Dynamic programming problem
int[][] dp = new int[m][n];
// First fill in the first line
for(int i = 0;i<n;i++){
dp[0][i] = 1;
}
// Fill in the first column
for(int i = 0;i<m;i++){
dp[i][0] = 1;
}
// Walk the inner ring
for(int i = 1;i<m;i++){
for(int j = 1;j<n;j++){
// Shortest path
// dp[i][j] = Math.max(dp[i-1][j],dp[i][j-1])+1;
// How many paths in total
dp[i][j] = dp[i-1][j] + dp[i][j-1];
}
}
return dp[m-1][n-1];
}
}
边栏推荐
- 2022年金属非金属矿山提升机操作考试题库及答案
- Neo 黑客松获奖名单揭晓,上万美金花落谁家?
- Today, 19:30 | graphics special session - Gao Lin, teacher team of Institute of computing technology, Chinese Academy of Sciences
- 无心剑中译拜伦诗4首
- 62. 不同路径-动态规划
- 九、委托模式
- Market development details of NFT casting trading platform
- Microsoft exposes another "scandal": watching VR porn in the office, "the father of hololens" is about to leave!
- Requirements and business model analysis - Requirements 17- requirements management
- 【边缘检测】基于matlab八方向sobel图像边缘检测【含Matlab源码 1865期】
猜你喜欢

威纶通触摸屏直接与台达变频器进行MODBUS RTU通信的具体方法(图文)

To serve the "nervous system" with a broad and subtle vision

Fastadmin uses phpexcel to export tabular data to excel

金融风控实战——异常检测(一)

Phpstrom télécharge le projet dans le cloud de code

Design of smart home control system (onenet) based on stm32_ two thousand and twenty-two

混音器:视频会议录制不可或缺的组件

"Isolation insurance" has become a "net red" product, but many policyholders say that it is difficult to settle claims
![[497. random points in non overlapping rectangles]](/img/c7/5e3e7bf1a78332aff4d2d42d6f826e.png)
[497. random points in non overlapping rectangles]

Delphi中的冷门知识点
随机推荐
Some problems in using message queue service in thinkphp6
[essay for college entrance examination season] I have something to say about the college entrance examination
Mongodb publishes "queryable encryption" system
2022年煤矿井下电气考试题库及在线模拟考试
[model basis] RNN | LSTM
Do you know all the wonderful functions of the vlookup function?
力扣 1037. 有效的回旋镖
创建swift颜色类
axure弹框设置
Bing's website search site: < domain name>< search content>
Uncaught TypeError: Cannot read properties of undefined (reading ‘colspan‘)
威纶通触摸屏直接与台达变频器进行MODBUS RTU通信的具体方法(图文)
2023王道C语言训练营(二叉查找树-顺序查找-折半查找)
[interesting reading] deepinf: social influence prediction with deep learning
Browser cache forbidden explanation
[image denoising] image denoising based on MATLAB bdcnn [including Matlab source code 1866]
2023王道C语言训练营(线索二叉树)
MongoDB 发布“可查询加密”系统 Queryable Encryption
今天19:30 | 图形学专场——中国科学院计算技术研究所高林老师团队
【730. 统计不同回文子序列】