Unique Paths
2016-07-01 19:15
369 查看
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.
解题思路:
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.
解题思路:
15 | 10 | 6 | 3 | 1 |
5 | 4 | 3 | 2 | 1 |
1 | 1 | 1 | 1 | 1 |
public int uniquePaths(int m, int n) { if(m == 0 && n == 0) return 0; int arr[][] = new int[m] ; for(int j = 0; j < n; j ++) arr[m-1][j]=1; for(int i = 0; i < m; i ++) arr[i][n-1]=1; for(int i = m-2; i >= 0; i --){ for(int j = n-2; j >= 0; j --){ arr[i][j]=arr[i+1][j]+arr[i][j+1]; } } return arr[0][0]; }
相关文章推荐
- duilib中类库结构及各控件响应的消息类型
- Android 高级UI设计笔记18:实现圆角图片
- HDOJ 5204 Rikka with sequence
- easyui改变tree的字体颜色,大小。
- Process 'command 'D:\android-ndk-r10\ndk-build.cmd'' finished with non-zero exit value 2
- 转: Vue.js——60分钟组件快速入门(上篇)
- MSBuild学习总结
- 自定义freemarker标签实现TemplateDirectiveModel时获取request
- git-gui:使用终端打开以后出现错误提示 Spell checking is unavable
- ****php:require_once(dirname(__FILE__)."/./config_uc.php");
- 调用相机 实现:视频录制,拍照 保存 上传服务器 UIImagePickerController AVPlayer
- Arduino那些事儿
- Commons Configuration2 - Quick start guide
- DelayQueue 学习和应用
- kafka connector commit 失败
- clone和clone(true)的差别
- easyui 执行添加操作,不使用弹窗而使用跳转新页面的方法
- 改变UIButton 图片和文字的位置
- umeditor、ueditor的使用
- title获得该标签的value