LeetCode Unique Paths
2015-04-08 20:45
323 查看
题目如下:
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.
这题其实非常简单,放着就是为了描述动态规划算法。看了代码就明白了。
类似的题Minimum Path Sum也可以通过这个方法解决。
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.
这题其实非常简单,放着就是为了描述动态规划算法。看了代码就明白了。
int uniquePaths(int m, int n) { int *A; A=(int*)malloc(sizeof(int)*m*n); int a,b; for(a=m-1,b=0;b<n;b++){ A[a*n+b]=1; } for(b=n-1,a=0;a<m;a++){ A[a*n+b]=1; } for(a=m-2;a>=0;a--){ for(b=n-2;b>=0;b--){ A[a*n+b]=A[(a+1)*n+b]+A[a*n+b+1]; } } return A[0]; }
类似的题Minimum Path Sum也可以通过这个方法解决。
相关文章推荐
- 【LeetCode】Unique Paths
- [LeetCode] Unique Paths-动态规划
- [LeetCode]Unique Paths
- LeetCode-62-Unique Paths
- LeetCode-Unique Paths
- [leetcode][DP] Unique Paths
- LeetCode Unique Paths
- 算法分析与设计——LeetCode Problem.62 Unique Paths
- leetcode_question_62 Unique Paths
- leetcode---62. Unique Paths
- 【leetcode】Unique Paths(动态规划)
- leetcode Unique Paths
- 【Leetcode】Unique Paths
- 27_leetcode_ Unique Paths
- 【LeetCode】Unique Paths
- [LeetCode] Unique Paths
- [LeetCode] Unique Paths
- LeetCode: Unique Paths
- LeetCode | Unique Paths【摘】
- leetcode 62: Unique Paths