62. Unique Paths 类别:动态规划 难度:medium
来源:互联网 发布:生猛海鲜知乎 编辑:程序博客网 时间:2024/06/04 19:01
题目:
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?
思路:
对于格点(i,j)。由于只能从上格点(i-1,j)或左格点(i,j-1)到达,并且两者路径是不重复的,因此path[i][j] = path[i-1][j]+path[i][j-1]。
程序:
class Solution {public: int uniquePaths(int m, int n) { vector<vector<int> > res(m + 1, vector<int>(n + 1, 1)); for(int i = 2;i <= m;i++) { for(int j = 2;j <= n;j++) res[i][j] = res[i - 1][j] + res[i][j - 1]; } return res[m][n]; }};
0 0
- 62. Unique Paths 类别:动态规划 难度:medium
- 63. Unique Paths II 类别:动态规划 难度:medium
- 96. Unique Binary Search Trees 类别:动态规划 难度:medium
- 120. Triangle 类别:动态规划 难度:medium
- 357. Count Numbers with Unique Digits 类别:动态规划 难度:medium
- 动态规划——62. Unique Paths[medium]
- Leetcode解题笔记 62. Unique Paths [Medium] 动态规划
- LeetCode-62-Unique Paths(动态规划)-Medium
- 413. Arithmetic Slices 类别:动态规划 难度:Medium
- 377. Combination Sum IV 类别:动态规划 难度:medium
- 300. Longest Increasing Subsequence 类别:动态规划 难度:medium
- 264. Ugly Number II 类别:动态规划 难度:medium
- 343. Integer Break 类别:动态规划 难度:medium
- 416. Partition Equal Subset Sum 类别:动态规划 难度:medium
- 64. Minimum Path Sum 类别:动态规划 难度:medium
- 376. Wiggle Subsequence 类别:动态规划 难度:medium
- Leetcode解题笔记 63. Unique Paths II [Medium] 动态规划
- 62. Unique Paths -Medium
- 操作系统总结(七)死锁
- 《生活中的脚本》- 过年回家如何省钱地给孩子们发红包~
- LibSVM for Python 使用
- 【编程之美】之初探Struts1
- jQuery_属性过滤选择器
- 62. Unique Paths 类别:动态规划 难度:medium
- PAT-甲级-1007
- R:混淆矩阵
- Sort Colors
- vs2013+opencv Mat图像显示到picture control控件
- Leetcode 405: Convert a Number to Hexadecimal
- HTTP 状态码
- ZOJ3203 Light Bulb[三分/推公式]
- 新书终于上市,小小炫耀一下