Unique Paths ——LeetCode
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.
题目大意:给定一个棋盘,从左上走到右下,一步走一个格,只能往右或往下走,问有多少种不同的走法。
解题思路:简单的动规,递推公式F(i,j)=F(i-1,j)+F(i,j-1),初始值F(0,0)=1。
public class Solution {
public int uniquePaths(int m, int n) {
int[][] cnt = new int[m][n];
cnt[0][0]=1;
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
if(i==0&&j==0)
continue;
if(i==0&&j!=0){
cnt[i][j]=cnt[i][j-1];
}
else if(j==0&&i!=0){
cnt[i][j]=cnt[i-1][j];
} else {
cnt[i][j]=cnt[i-1][j]+cnt[i][j-1];
}
}
}
return cnt[m-1][n-1];
}
}
Unique Paths ——LeetCode的更多相关文章
- Unique Paths [LeetCode]
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The ...
- Unique Paths leetcode java
题目: A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). ...
- [LeetCode] Unique Paths II 不同的路径之二
Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...
- [LeetCode] Unique Paths 不同的路径
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The ...
- LeetCode: Unique Paths II 解题报告
Unique Paths II Total Accepted: 31019 Total Submissions: 110866My Submissions Question Solution Fol ...
- LeetCode: Unique Paths I & II & Minimum Path Sum
Title: https://leetcode.com/problems/unique-paths/ A robot is located at the top-left corner of a m ...
- LeetCode 62. Unique Paths(所有不同的路径)
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The ...
- 【一天一道LeetCode】#63. Unique Paths II
一天一道LeetCode (一)题目 Follow up for "Unique Paths": Now consider if some obstacles are added ...
- 【一天一道LeetCode】#62. Unique Paths
一天一道LeetCode系列 (一)题目 A robot is located at the top-left corner of a m x n grid (marked 'Start' in th ...
随机推荐
- MyTask2
先把核心代码贴上 public void solve() { //Console.WriteLine("请输入你需要生成多少人的数据以及年龄最大值(75以内):"); //int ...
- css3购物网站商品文字提示实例
css3购物网站商品文字提示实例先来看效果图:<ignore_js_op> 当鼠标划过图片时,有着泰迪熊黑色长方形的背景就会出现.来看HTML5+CSS3代码: <!DOCTYPE ...
- jQuery注册验证
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- android EventBus 的使用
今天简单的介绍 一下啊 android EventBus 的使用 EventBus 在官方介绍中是订阅......什么的 一大堆 , 在我android 菜鸟眼里 就是用来代替android 广 ...
- jquery,javascript -设置某一ul下的li下的 a的属性
//javascriptvar ul = document.getElementById('ul); var as = ul.getElementsByTagName('a'); for(var i ...
- (转载)loadrunner简单使用——HTTP,WebService,Socket压力测试脚本编写
原文出处:http://ajita.iteye.com/blog/1728243/ 先说明一下,本人是开发,对测试不是特别熟悉,但因工作的需要,也做过一些性能测试方面的东西.比较久之前很简单的用过,最 ...
- JAVA JDK 1.6 API中文版.CHM打开chm提示,“ 已取消到该网页的导航”
JAVA JDK 1.6 API中文版.CHM打开chm提示,“ 已取消到该网页的导航” silent fish 装了win7后,打开chm文件,发现很多在xp系统打开正常的chm文件竟然出现问题, ...
- VMware Workstation 11序列号一枚
VMware Workstation 11序列号: 1F04Z-6D111-7Z029-AV0Q4-3AEH8
- CI 笔记(easyui js命令)
1. 两种方式加载easyui,一是用class自动渲染,一种是js.建议js. 2. 参考李炎恢的easyui的视频教程.最好的一个视频,对于easyui.
- 【转载】C++应用引用计数技术
原帖:http://www.cnblogs.com/chain2012/archive/2010/11/12/1875578.html 因为Windows的内核对象也运用了引用计数,所以稍作了解并非无 ...