动态规划——unique-paths
来源:互联网 发布:qq飞车8周年剃刀数据 编辑:程序博客网 时间:2024/06/10 16:29
题目描述
一个m x n的矩阵,机器人从左上角走到右下角总共有多少种走法。
注:每次只能向下或向右走一格。
递归例程:
public class Solution { public int uniquePaths(int m, int n) { if(m < 1||n < 1) return 0; return help(0,0,m,n); } public int help(int x,int y,int m,int n) { if(x == m-1||y == n-1) return 1; else return help(x+1,y,m,n)+help(x,y+1,m,n); }}
DP例程:
public int uniquePaths(int m, int n) { if(m < 1||n < 1) return 0; int[][] dp=new int[m][n]; //初始化 for(int j=0;j<n;j++) dp[m-1][j]=1; for(int i=0;i<m;i++) dp[i][n-1]=1; for(int i=m-2;i>=0;i--) { for(int j=n-2;j>=0;j--) { dp[i][j]=dp[i+1][j]+dp[i][j+1]; } } return dp[0][0]; }
0 0
- 动态规划——unique-paths
- 动态规划——unique-paths-ii
- 蘑菇阵(动态规划、百度)——unique paths
- 动态规划——62. Unique Paths[medium]
- 算法题——Unique Paths(C++)动态规划
- Leetcode 动态规划 Unique Paths
- [LeetCode] Unique Paths-动态规划
- [LeetCode]Unique Paths (动态规划)
- Unique Paths 动态规划(重重)
- Leetcode 动态规划 Unique Paths II
- LeetCode Unique Paths 动态规划与大数
- 53.Unique Paths(动态规划)
- LeetCode-62-Unique Paths(动态规划)-Medium
- 62. Unique Paths 动态规划算法浅谈
- [leetcode]unique-paths 动态规划 C++
- 动态规划问题系列---Unique Paths II
- [LeetCode]62. Unique Paths&&动态规划
- 03动态规划-02unique-paths
- DirectX 在MFC框架下的应用
- JUnit的各种断言
- unity 打包IPA,减少文件大小的方法
- JUnit中常用的接口和类
- Note1
- 动态规划——unique-paths
- 字符数组,字符指针,字符串常量
- 【gradle】问题及解决
- safari无痕模式localStorage报错
- Sketch设计UI的知识总结
- Cygwin 简介和入门
- Volley 源码解析
- Android SDK 国内镜像
- readhat-解决This system is not registered with RHN