2019独角兽企业重金招聘Python工程师标准>>>

题目内容

[引自] https://leetcode.com/problems/unique-paths/description/

A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).

The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).

How many possible unique paths are there?

Above is a 3 x 7 grid. How many possible unique paths are there?

Note: m and n will be at most 100.

伪代码

核心: uniquePaths(i,j)=uniquePaths(i-1,j)+uniquePaths(i,j-1)
states数组保存状态值 states[i][j]表示到达i,j位置的不同路径数
边界值:初始边界为(0,x)和 (x,0)
初始化: states[0][0]=0,states[0][x]=0,states[x][0]=0
(1,1)表示初始位置,states[1][1]=0,states[1][2]=1,states[2][1]=1

算法

int uniquePaths(int m, int n)int[][] states =new int[101][101]states[1][1]=1for  i=1 to m+1for j=1 to n+1if(i==1 and j==1)continue;states[i][j]=states[i-1][j]+states[i][j-1]states[1][1]=0return states[m][n]

java 代码实现

    public int uniquePaths(int m, int n) {int[][] states =new int[101][101];states[1][1]=1;for(int i=1;i<m+1;i++){for(int j=1;j<n+1;j++){if(i==1&&j==1){continue;}states[i][j]=states[i-1][j]+states[i][j-1];}}states[1][1]=0;return states[m][n];}

转载于:https://my.oschina.net/u/3706181/blog/1605610

动态规划练习1--Unique Paths相关推荐

  1. leetcode 62, 63, 980. Unique Paths I, II, III | 62, 63, 980. 不同路径 I, II, III(暴力递归->傻缓存->动态规划)

    62. Unique Paths https://leetcode.com/problems/unique-paths/ 注意本题只能向右 / 向上走. DP 问题,经典又熟悉. 暴力递归->傻 ...

  2. 【动态规划】LeetCode 62. Unique Paths

    LeetCode 62. Unique Paths Solution1:我的未能AC的答案 递归超时了!!! class Solution { public:int uniquePaths(int m ...

  3. 10.2 动态规划算法套路及空间优化 —— Climbing Stairs Unique Paths

    这一篇文章从最简单的动态规划题目开始,结合上一节动态规划三要素,以LeetCode两道基础的DP题目阐述DP问题的基本套路解法. 70. Climbing Stairs You are climbin ...

  4. 【动态规划】LeetCode 63. Unique Paths II

    LeetCode 63. Unique Paths II Solution1:我的答案 在哪里做过这题? class Solution { public:int uniquePathsWithObst ...

  5. Leetcode 62. Unique Paths

    题目: A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). ...

  6. [LeetCode]: 62: Unique Paths

    题目: A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). ...

  7. leetcode 【 Unique Paths 】python 实现

    题目: A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). ...

  8. 63. Unique Paths II and 64. Minimum Path Sum

    文章目录 1 63 Unique Paths II 1.1 题目描述 1.2 动态规划解决 2 64. Minimum Path Sum 2.1 题目理解 2.2 动态规划 这一遍刷dp的题目就很轻松 ...

  9. LeetCode62 Unique Paths

    题目: A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). ...

  10. LeetCode 1.Minimum Path Sum 2.Unique Paths I and II

    大家好,我是刘天昊,快到端午节了,今天说两道动态规划的题目(话说动规真的挺难的) 当然这三题是一样的解体思路先看Unique Paths A robot is located at the top-l ...

最新文章

  1. windows 10 代理服务器出现问题
  2. Nginx学习之五:Nginx第三方模块
  3. Nginx(六)-- 配置文件之Gzip
  4. [react] 举例说明useState
  5. 学习笔记3-C语言-基础
  6. springboot2——MyBatis入门
  7. 划重点!DWS开发的五大要点
  8. yii2 关掉php notice,php – 使用Yii2中的自动填充更新隐藏字段
  9. TC SRM 665 DIV2 B LuckyCycle 暴力
  10. 大师之路解惑基础概念篇:Tomcat与servlet联系与区别
  11. linux 关机自动重启,自己动手解决了Ubuntu关机后自动重启
  12. matlab实现色彩迁移,图像的色彩风格迁移
  13. 系统试运行报告是谁写的_深圳个人信用报告查询系统入口https://ipcrs.pbccrc.org.cn/...
  14. C#【EF Core框架】使用乐观锁处理并发冲突
  15. 飞腾cpu服务器浪潮信息,浪潮发布基于国产飞腾CPU的服务器
  16. 简单的图片轮播器(一):一个关于仿flash的图片轮换器
  17. Flex布局——flex-basis、flex-grow、flex-shrink
  18. 创意信息子公司作为华为合作伙伴 携产品登录华为云端展厅
  19. ARM NandFlash 介绍
  20. python 写出好看且实用的后台管理-django 后台管理美化

热门文章

  1. RAID和mdadm
  2. UISlider 滑竿控件
  3. 转:Tkinter教程之Text(2)篇
  4. android平台水波效果 源码
  5. 性能测试应用领域分析
  6. FreeSwitch 的初始化及其模块加载过程
  7. Command模式的实践
  8. S60 V3版SDK的官方扩展插件
  9. eplise怎么连接数据库_如何通过eclipse连接到mysql数据库
  10. tomcat启动出现闪退_(转)Tomcat 启动后 “闪退”