[LeetCode]Unique Paths
2015-08-19 18:15
405 查看
题目
Number: 62Difficulty: Medium
Tags: Array, Dynamic Programming
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?
题解
经典的动态规划问题。m*n的矩阵,从
(0, 0)到
(m-1, n-1)有多少种路径。
代码
[code]int uniquePaths(int m, int n) { vector<vector<int>> path(m, vector<int>(n, 1)); for(int i = 1; i < m; i++){ for(int j = 1; j < n; j++){ path[i][j] = path[i][j - 1] + path[i - 1][j]; } } return path[m - 1][n - 1]; }
相关文章推荐
- StringBuffer和StringBuilder的区别
- UIViewController的详细介绍
- iOS UIScrollView实现无限滚动,思路与代码
- iOS:UITextField中文输入法输入时对字符长度的限制
- 将webkit内核封装为duilib的浏览器控件
- 分享个Duilib中基于wke的浏览器控件
- HDU 2767--Proving Equivalences【scc缩点构图 && 求向图中最少增加多少条边才可以使新图强连通】
- sql server UI怎么设置自增加id?
- iOS SDK详解之UIToolBar
- 树莓派2在U8300W平台上用pppd拨号时出现“pppd: The remote system is required to authenticate itself”
- mysql 错误 SQL Error: 1366: Incorrect string value: "\xE8\xAF\xA6\xE7\xBB\x86…" for column "address"
- class priority_queue<> 简单介绍
- 多线程之四:NSOperation与NSOperationQueue
- quicksumpoj
- IOS第11天(4:UIDatePicker时间选择,和键盘处理,加载xib文件,代理模式)
- 小胖说事37-----iOS基础知识之UIScrollview的代理和Build Active Architecture Only属性
- String,StringBuffer与StringBuilder的区别??
- Ueditor编辑器的使用
- 算法(二)—分治法Divide-and-conque
- 逗比的坑——for (int i = 0; gc_handDataOutput->QueryNumberOfHands(); ++i)