当前位置:网站首页>leetcode 62. Unique Paths(独特的路径)
leetcode 62. Unique Paths(独特的路径)
2022-08-02 09:17:00 【蓝羽飞鸟】

出发点在左上角,目的地在右下角,问从出发点到目的地有多少不同的路径。
思路:
典型的DP
dp[i][j]表示到达(i, j)处有多少条不同的路径。
第1行和第一列显然只有一条路径。
然后因为只能向右和向下运动,所以dp[i][j]来自于它上方和左方的路径个数
dp[i][j] = dp[i-1][j] + dp[i][j-1]
public int uniquePaths(int m, int n) {
int[][] dp = new int[m][n];
for(int i = 0; i < m; i++) dp[i][0] = 1;
for(int j = 0; j < n; j++) dp[0][j] = 1;
for(int i = 1; i < m; i++) {
for(int j = 1; j < n; j++) {
dp[i][j] = dp[i-1][j] + dp[i][j-1];
}
}
return dp[m-1][n-1];
}
边栏推荐
猜你喜欢

不用Swagger,那我用啥?
![[Must read] Mylander valuation analysis, electrical stimulation products for pelvic and postpartum rehabilitation](/img/25/e16bac4e789cddadffd43ed9e9df7c.jpg)
[Must read] Mylander valuation analysis, electrical stimulation products for pelvic and postpartum rehabilitation

自定义卡包效果实现

自定义View实现波浪荡漾效果

pnpm: Introduction

边缘计算开源项目概述

Jetpack Compose 中的状态管理

曲折的tensorflow安装过程(Tensorflow 安装问题的解决)

天地图给多边形加标注

The use of thread pool and analysis of ThreadPoolExecutor source code
随机推荐
你有了解过这些架构设计,架构知识体系吗?(架构书籍推荐)
记某社区问答
What attributes and methods are available for page directives in JSP pages?
leetcode:639. 解码方法 II
LeetCode第三题(Longest Substring Without Repeating Characters)三部曲之一:解题思路
ABAP 和json转换的方法
Jenkins--基础--07--Blue Ocean
SAP 云平台上一种 Low Code Development(低代码开发)解决方案
tf.where使用
C Language Basics_Union
location对象,navigator对象,history对象学习
单词接龙 II
Spend 2 hours a day to make up for Tencent T8, play 688 pages of SSM framework and Redis, and successfully land on Meituan
Rust from entry to master 03-helloworld
MySQL安装与卸载详细教程
JS中的数组方法
Qt读取文件中内容(通过判断GBK UTF-8格式进行读取显示)
(Note) AXIS ACASIS DT-3608 Dual-bay Hard Disk Array Box RAID Setting
2022牛客暑期多校训练营4(ADHKLMN)
Jenkins--基础--6.3--Pipeline--语法--脚本式