LeetCode:Unique Paths
2016-01-07 16:01
399 查看
Unique Paths
My SubmissionsQuestion
Total Accepted: 72643 Total
Submissions: 208792 Difficulty: Medium
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?
![](http://leetcode.com/wp-content/uploads/2014/12/robot_maze.png)
Above is a 3 x 7 grid. How many possible unique paths are there?
Note: m and n will be at most 100.
Subscribe to see which companies asked this question
Hide Tags
Array Dynamic
Programming
Show Similar Problems
很简单,状态转移表:
m = 3, n = 7
1 | 1 | 1 | 1 | 1 | 1 | 1 |
1 | 2 | 3 | 4 | 5 | 6 | 7 |
1 | 3 | 6 | 10 | 15 | 21 | 28 |
dp[i][j] = dp[i-1][j] + dp[i][j-1]
code:
class Solution { public: int uniquePaths(int m, int n) { //int dp[m] ; vector<vector<int>> dp(m, vector<int>(n)); for(int i=0;i<m;i++) dp[i][0] = 1; for(int j=0;j<n;j++) dp[0][j] = 1; for(int i=1;i<m;i++) for(int j=1;j<n;j++) dp[i][j] = dp[i-1][j] + dp[i][j-1]; return dp[m-1][n-1]; } };
相关文章推荐
- duilib库-----消息流程分析
- IOS之未解问题--给UITableView提取UITableViewDataSource并封装瘦身失败
- C#Question:“XXX”的重载均与“System.Threading.WaitCallback”不匹配。
- 9.UITextField的基本使用
- 三种方式实现在一个Activity中控制另一个Activity的UI的更新
- UILabel使用不同的大小和字体、颜色
- 8.UIView的基本使用
- Egret)Demo - eui state自定义状态的使用
- 机器视觉学习笔记(8)——基于OpenCV的Bouguet立体校正
- iOS UIViewController的生命周期
- 7.UIScrollView的基本使用
- duilib学习笔记
- 6.UIAlertView的基本使用
- Listview最后一行被覆盖的bug
- easyui datagrid 分页保持checkbox选中状态
- easyui-tab href,content区别
- build.xml:278: Unable to find a javac compiler;
- NSInteger、NSUInteger、CGFloat
- Scapy + Nfqueue
- iOS - UITextField代理方法详解(调用顺序)