LeetCode *** 62. Unique Paths
2016-04-12 19:35
399 查看
题目:
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.
分析:
动态规划即可。
代码:
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.
分析:
动态规划即可。
代码:
class Solution { public: int uniquePaths(int m, int n) { int dp[m+1][n+1]={0}; dp[1][1]=1; for(int i=1;i<m+1;++i) for(int j=1;j<n+1;++j){ if(i>1)dp[i][j]+=dp[i-1][j]; if(j>1)dp[i][j]+=dp[i][j-1]; } return dp[m] ; } };
相关文章推荐
- 62. Unique Paths
- easyUI框架下实现日期按年,年月,年月日方式显示
- 文章标题WERTYUIOP[ 每日一到算法题]
- D. Longest Subsequence
- D. Longest Subsequence
- Java之——生成短8位UUID
- 利用localStorage实现对ueditor编辑内容定时保存为草稿
- Cannot assign requested address解决办法
- uva 1152 4 values whose sum is zero ——yhx
- Light OJ 1061 N Queen Again
- 对于初学iOS开发者有用之在UITableView的导航栏中加入Item的方法
- HUE配置zookeeper,HDFS报错Failed to access filesystem root解决
- runOnUiThread-----startAnimation
- mybatis result maps collection already contains value解决办法
- iOS 基于runtime 解决UIButton重复点击 发送多次请求问题
- You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE)
- HDOJ 3836 Equivalent Sets
- UITextField的部分自定义设置
- android AsyncQueryHandler的分析
- Freemaker:you just want "true"/"false" result as you are generting computer-language output, use "?c