当前位置:网站首页>A robot is located in the upper left corner of an M x n grid. The robot can only move down or right one step at a time. The robot attempts to reach the lower right corner of the grid. How many differe
A robot is located in the upper left corner of an M x n grid. The robot can only move down or right one step at a time. The robot attempts to reach the lower right corner of the grid. How many differe
2022-06-27 16:13:00 【Small skeleton】
Force deduction hot question 100 And 62:

Post the code first :
class Solution {
public int uniquePaths(int m, int n) {
// Create a chessboard
int[][] board = new int[m][n];
// Will be the first 0 The grid path of the column is set to 1
for (int i = 0; i < m; i++) {
board[i][0] = 1;
}
// Will be the first 0 The grid path of the row is set to 1
for (int j = 0; j < n; j++) {
board[0][j] = 1;
}
// Accumulate the number of paths in the grid
for (int i = 1; i < m; i++) {
for (int j = 1; j < n; j++) {
board[i][j] = board[i-1][j] + board[i][j-1];
}
}
return board[m-1][n-1];
}
}Their thinking :
The title tells us , You need to reach the end of the chessboard ( The lower right corner ), And the robot can only move right or down one step at a time , So when we reach a grid , It can only come from its left or top , From this we can infer that :
The number of paths to a grid = The number of paths to the left of this grid + The number of paths to the upper grid of this grid ;
That is, the expression is : f( i , j ) = f( i - 1 , j ) + f( i , j - 1 );
Let's start with the 0 Xing He 0 The cells of the column are all set to 1, It means that there is only one path from the starting point to these grids , Let's take one 3 * 6 Example of chessboard :
Then start to calculate the number of paths of the remaining blank grids in turn , Because the expression is known from the above :
f( i , j ) = f( i - 1 , j ) + f( i , j - 1 );
So when finding the number of paths in a lattice , Just put the left pane + Upper grid that will do . Find that the number of paths in the remaining lattice is :

It can be concluded that The number of paths to the destination is 15 + 6 = 21 !
边栏推荐
- 等保三级密码复杂度是多少?多久更换一次?
- 如果想用dms来处理数据库权限问题,想问下账号只能用阿里云的ram账号吗(阿里云的rds)
- 关于#mysql#的问题:问题遇到的现象和发生背景
- About fast exponentiation
- Cesium uses mediastreamrecorder or mediarecorder to record screen and download video, as well as turn on camera recording. [transfer]
- 是不是只要支持JDBC / ODBC协议的客户端恐惧,PolarDB-X可通过相关工具的客户端访问?
- Hung - Mung! HDD Hangzhou station · salon hors ligne vous invite à construire l'écologie
- 智慧风电 | 图扑软件数字孪生风机设备,3D 可视化智能运维
- 事件监听机制
- PSS:你距離NMS-free+提點只有兩個卷積層 | 2021論文
猜你喜欢

What is RPC

Julia constructs diagonal matrix

树莓派初步使用

List to table

Construction and management practice of ByteDance buried point data flow
![Luogu_ P1008 [noip1998 popularization group] triple strike_ enumeration](/img/9f/64b0b83211bd1c615f2db9273bb905.png)
Luogu_ P1008 [noip1998 popularization group] triple strike_ enumeration

IDE Eval reset unlimited trial reset

【牛客刷题】NowCoder号称自己已经记住了1-100000之间所有的斐波那契数。 为了考验他,我们随便出一个数n,让他说出第n个斐波那契数。如果第n个斐波那契大于6位则只取后6位。

带你认识图数据库性能和场景测试利器LDBC SNB

继手机之后 报道称三星也削减了电视等家电产品线的产量
随机推荐
A distribution fission activity is more than just a circle of friends!
LeetCode每日一练(杨辉三角)
QT5 之信号与槽机制(演示控件自带的信号与槽函数关联)
数据中心表格报表实现定制统计加班请假汇总记录分享
The array of C language is a parameter to pass a pointer
Principle Comparison and analysis of mechanical hard disk and SSD solid state disk
The interview lasted for half a year. Last month, I successfully got Alibaba p7offer. It was all because I chewed the latest interview questions in 2020!
防火墙基础之源NAT地址转换和服务器映射web页面配置
Li Chuang EDA learning notes 16: array copy and array distribution
Sigkdd22 | graph generalization framework of graph neural network under the paradigm of "pre training, prompting and fine tuning"
What is the level 3 password complexity of ISO? How often is it replaced?
跨域图像的衡量新方式Style relevance:论文解读和代码实战
守护雪山之王:这些AI研究者找到了技术的新「用武之地」
基于 Nebula Graph 构建百亿关系知识图谱实践
New method of cross domain image measurement style relevance: paper interpretation and code practice
ICML 2022 | 阿⾥达摩院最新FEDformer,⻓程时序预测全⾯超越SOTA
Google Earth Engine(GEE)——Export. image. The difference and mixing of toasset/todrive, correctly export classification sample data to asset assets and references
QT5.5.1桌面版安装配置过程中的疑难杂症处理(配置ARM编译套件)
PolarDB-X现在版本的开源兼容什么?mysql8?
Centos8 PostgreSQL initialization error: initdb: error: invalid locale settings; check LANG and LC_* environment