Leetcode-unique-paths
来源:互联网 发布:mac qq代理服务器 编辑:程序博客网 时间:2024/06/01 22:45
题目描述
A robotis located at the top-left corner of a m x n grid (marked 'Start' in the diagrambelow).
The robotcan only move either down or right at any point in time. The robot is trying toreach the bottom-right corner of the grid (marked 'Finish' in the diagrambelow).
How many possibleunique paths are there?
Above isa 3 x 7 grid. How many possible unique paths are there?
Note: m and n will be at most 100.
这个题目是最典型的动态规划了,经过前一段时期的训练,这样的题目终于是会做了,但是在坐标index的操作上需要多加注意,就是从(1,1)出发到(m,n),或者(0,0)出发到(n-1,m-1),两种表示方法都可以,需要注意的就是index怎么操作。
public class Solution { public int uniquePaths(int m, int n) { int[][] dp =new int[m][n]; dp[0][0] = 1; for(int i=1;i<m; i++){ dp[i][0] = 1; } for(int j=1;j<n; j++){ dp[0][j] = 1; } for(int i=1;i<m; i++){ for(int j=1; j<n; j++){ dp[i][j] =dp[i-1][j]+dp[i][j-1]; } } return dp[m-1][n-1]; }}
我在想的是,如果题目中给出一些限制条件,比如说地图中有一些地方是封闭的,不可以经过,如(2,2)这一点无法通过,求在这种情况下的方案个数。我需要thinkthink。
0 0
- leetcode Unique Paths && Unique Paths
- Leetcode-Unique Paths&Unique PathsII
- [LeetCode] Unique Paths and Unique Paths II
- leetcode--Unique Paths && Unique Paths ii
- leetcode--Unique Paths && Unique Paths ii
- 【Leetcode】【python】Unique Paths/Unique Paths II
- LeetCode: Unique Paths
- LeetCode: Unique Paths II
- [Leetcode] Unique Paths
- [Leetcode] Unique Paths II
- LeetCode : Unique Paths
- LeetCode : Unique Paths II
- leetcode 9: Unique Paths
- [LeetCode] Unique Paths
- [LeetCode] Unique Paths II
- [LeetCode]Unique Paths
- [LeetCode]Unique Paths II
- [LeetCode] Unique Paths
- 现代控制理论2
- PV,UV,VV,IP解析
- APM (应用性能管理)
- 最全面的Java面试题-----是你更好的掌握java知识
- 经过show variables like xxx 详解mysql运行时参数
- Leetcode-unique-paths
- Leetcode-count-and-say
- 如何有效的结束项目--对某税务MIS系统项目的经验总结
- android.graphics.Camera API 中文翻译
- AOE网络的算法,活动的最早开始时间,最晚结束时间,关键活动,关键路径
- 在Windows系统下,搭建最简单的nginx服务器
- 浅谈web应用的负载均衡、集群、高可用(HA)解决方案
- js实现动画,右移、左移,上移,下移,左上角移动等
- 数据库设计案例分析