leetcode oj java Unique Paths
来源:互联网 发布:tensorflow viterbi 编辑:程序博客网 时间:2024/05/16 19:09
一、问题描述:
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.
二、解决思路:
1很容易想到递归: f(m,n) = f(m-1,n) + f(m,n-1) , 终止条件是m==1 || n==1但是time limit
2动态规划,: 用二维数组存放路径数目, a[m][n] = a[m-1][n] + a[m][n-1]
三、代码:
package T12;/** * @author 作者 : xcy * @version 创建时间:2016年12月20日 下午3:42:16 * 类说明 */public class t62 { public static int re = 0; public static void main(String[] args) { // TODO Auto-generated method stub System.out.println(uniquePaths(10, 10)); } // public static int uniquePaths(int m, int n) { // if (m == 1 || n == 1) { // return 1; // } // return uniquePaths(m - 1, n) + uniquePaths(m, n - 1); // } public static int uniquePaths(int m, int n) { int[][] re = new int[m][n]; for (int i = 0; i < m; i++) { re[i][0] = 1; } for (int j = 0; j < n; j++) { re[0][j] = 1; } for (int i = 1; i < m; i++) { for (int j = 1; j < n; j++) { re[i][j] = re[i - 1][j] + re[i][j - 1]; } } return re[m - 1][n - 1]; }}
0 0
- leetcode oj java Unique Paths
- LeetCode OJ:Unique Paths
- LeetCode OJ Unique Paths
- leetcode oj java Unique Paths II
- LeetCode OJ:Unique Paths II
- LeetCode OJ - Unique Paths II
- LeetCode OJ Unique Paths II
- LeetCode OJ 62. Unique Paths
- [Leetcode] Unique Paths (Java)
- [LeetCode][Java] Unique Paths
- LeetCode OJ 第63题Unique Paths ||
- LeetCode OJ-62. Unique Paths(DP)
- [Leetcode] Unique Paths II (Java)
- leetcode java Unique Paths II
- 【Leetcode】Unique Paths in JAVA
- [LeetCode][Java] Unique Paths II
- (Java)LeetCode-62. Unique Paths
- 【leetcode】62. Unique Paths【java】
- 解决 Windows 10 中的网络连接问题
- Oracle常用函数系列之八:聚合函数
- linux删除邮件
- 【BZOJ 2434】[Noi2011]阿狸的打字机 Ac自动机+树状数组+dfs序
- 微信小程序简单form提交自带判断
- leetcode oj java Unique Paths
- Arduino Uno 使用 人体红外传感器(HC_SR051)实现 人体感应灯
- Caffe学习系列(8):solver优化方法
- 全国各地DVB地面标准汇总(总结)
- 知识点一:三个实用的jQuery的DOM操作方法==>获取、替换
- 数据结构期末总结
- 【NOIP2017提高组模拟12.18】A
- C++11初始化列表与参数列表的作用
- web开发入门2---手动开发动态资源