当前位置:网站首页>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 !
边栏推荐
- express
- E modulenotfounderror: no module named 'psychopg2' (resolved)
- 鴻蒙發力!HDD杭州站·線下沙龍邀您共建生態
- Construction and management practice of ByteDance buried point data flow
- Four characteristics of transactions
- Etcd可视化工具:Kstone部署(一),基于Helm快速部署
- 16 -- remove invalid parentheses
- 继手机之后 报道称三星也削减了电视等家电产品线的产量
- QT5 之信号与槽机制(信号与槽的基本介绍)
- List转Table
猜你喜欢

28 object method extension

PSS: you are only two convolution layers away from the NMS free+ point | 2021 paper

Hongmeng makes efforts! HDD Hangzhou station · offline salon invites you to build ecology

防火墙基础之源NAT地址转换和服务器映射web页面配置
![Luogu_ P1003 [noip2011 improvement group] carpet laying_ Violence enumeration](/img/65/413ac967cc8fc22f170c8c7ddaa106.png)
Luogu_ P1003 [noip2011 improvement group] carpet laying_ Violence enumeration

3.2 multiple condition judgment

A distribution fission activity is more than just a circle of friends!

List to table

事务的四大特性

数据中心表格报表实现定制统计加班请假汇总记录分享
随机推荐
Relation and operation of ORM table
一场分销裂变活动,不止是发发朋友圈这么简单!
请问阿里云实验中 k8s 对于3306端口转发,同时开启mysql客户端就会异常终止,是什么原因呢?
16 -- remove invalid parentheses
What are the password requirements for waiting insurance 2.0? What are the legal bases?
Format of mobile number
OpenSSF安全计划:SBOM将驱动软件供应链安全
Pragma once Usage Summary
等保2.0密码要求是什么?法律依据有哪些?
Weekly snapshot of substrate technology 20220411
开源二三事|ShardingSphere 与 Database Mesh 之间不得不说的那些事
LeetCode每日一练(主要元素)
Design of FIR digital filter
QT5.5.1桌面版安装配置过程中的疑难杂症处理(配置ARM编译套件)
Etcd可视化工具:Kstone部署(一),基于Helm快速部署
泰山OFFICE技术讲座:第一难点是竖向定位
Luogu_ P1007 single log bridge_ thinking
Smart wind power | Tupu software digital twin wind turbine equipment, 3D visual intelligent operation and maintenance
带你认识图数据库性能和场景测试利器LDBC SNB
QT audio playback upgrade (7)