Unique Paths
2016-06-15 19:39
411 查看
题目描述:
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.
动态规划
public class Solution { public int uniquePaths(int m, int n) { int[][] area=new int[m] ; area[0][0]=1; for (int i = 1; i < n; i++) { area[0][i]=1; } for (int i = 1; i < m; i++) { area[i][0]=1; } for(int i=1;i<m;i++){ for(int j=1;j<n;j++) { area[i][j]=area[i-1][j]+area[i][j-1]; } } return area[m-1][n-1]; } }
相关文章推荐
- 232. Implement Queue using Stacks 还不理解法一
- 多线程更新UI的常用方法
- iOS学习之UINavigationController详解与使用(一)添加UIBarButtonItem
- Lightoj 1012 - Guilty Prince
- iOS UITextField的边框设置颜色的小坑
- IOS开发UIBarButtonItem-添加自定义Left或者Right按钮
- Codeforces 678F Lena and Queries
- Finished with non-zero exit value *
- UIViewController生命周期
- Java多线程15:Queue、BlockingQueue以及利用BlockingQueue实现生产者/消费者模型
- [javaSE] GUI(菜单)
- easy UI中利用JS获取当前月的第一天和最后一天,并显示到时间控件上
- Android 子线程更新UI
- MysqlDataTruncation: Data truncation: Incorrect datetime value
- uibutton 默认的边框 是方形的,如何把它的border设置它的圆角
- iOS开发之键盘类型UIKeyboardType
- uiautomatorviewer介绍
- Concurrency Managed Workqueue之(四):workqueue如何处理work
- Concurrency Managed Workqueue之(三):创建workqueue代码分析
- 解压本地zip,读取数据更新UI