[LeedCode OJ]#63 Unique Paths II
class Solution
{
public:
int uniquePathsWithObstacles(vector<vector<int> >& a)
{
int i,j;
int n = a.size(),m = a[0].size();
vector<vector<int> > dp;
dp.resize(n+1);
for(i = 0; i<=n; i++)
dp[i].resize(m+1);
dp[0][0] = !a[0][0];
for(i = 0; i<n; i++)
{
for(j = 0; j<m; j++)
{
if(i==0&&j==0) continue;
if(a[i][j]==1)
{
dp[i][j] = 0;
continue;
}
if(i == 0)
{
dp[i][j]=dp[i][j-1];
continue;
}
if(j == 0)
{
dp[i][j]=dp[i-1][j];
continue;
}
dp[i][j]=dp[i-1][j]+dp[i][j-1];
}
}
return dp[n-1][m-1];
}
};
[LeedCode OJ]#63 Unique Paths II的更多相关文章
- LeetCode OJ 63. Unique Paths II
Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...
- leetcode 62. Unique Paths 、63. Unique Paths II
62. Unique Paths class Solution { public: int uniquePaths(int m, int n) { || n <= ) ; vector<v ...
- 62. Unique Paths && 63 Unique Paths II
https://leetcode.com/problems/unique-paths/ 这道题,不利用动态规划基本上规模变大会运行超时,下面自己写得这段代码,直接暴力破解,只能应付小规模的情形,当23 ...
- 【LeetCode】63. Unique Paths II
Unique Paths II Follow up for "Unique Paths": Now consider if some obstacles are added to ...
- [LeetCode] 63. Unique Paths II 不同的路径之二
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
Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...
- 63. Unique Paths II
题目: Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. H ...
- 63. Unique Paths II(中等, 能独立做出来的DP类第二个题^^)
Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...
- 【一天一道LeetCode】#63. Unique Paths II
一天一道LeetCode (一)题目 Follow up for "Unique Paths": Now consider if some obstacles are added ...
随机推荐
- rem布局进入页面样式错乱解决
开发项目时候第一次遇到rem布局进入页面瞬间样式错乱问题: //该段js为rem布局应用 如10px = 0.1rem; (function(doc, win) { var docEl = doc.d ...
- STA之Concepts (2)
3 Skew between signals Skew is the difference in timing between two or more signals, maybe data, clo ...
- 梦想CAD控件打印相关
一.打印设置 在顶部快速访问工具栏单击打印按钮或者直接输入PLOT命令或者点击打印控制的打印设置按钮打开打印对话框.c#代码实现如下: //打印设置 private void Print1() { ...
- 使用lombok注解@Getter @Setter方法代码编译成功,但是没有生成get,set方法
现象描述: 在对应类对象中,添加lombok的@Getter或@Setter注解,编译没有问题,但是在使用类对象时,没有出现对应的get或set方法. 配置且编译ok,但是没有对应的get或set方法 ...
- ERROR: Field 'PostId' doesn't have a default value Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not execute statement
例子: Post p = new Post(); p.setPostId(3); p.setPostName("技术"); 在执行数据保持时提示session.save(p); 的 ...
- 元组tuple类型内置方法
目录 元组tuple类型内置方法 用途 定义 常用操作+内置方法 优先掌握 存一个值or多个值 有序or无序 可变or不可变 元组tuple类型内置方法 元组是不可变的列表,在定义完成后后面就不可以进 ...
- Python学习——字典
字典 字典是另一种可变容器模型,且可存储任意类型对象. 1.创建字典 字典由键和对应值成对组成.每个键与值之间用:隔开,每对之间逗号隔开. 每个键应当互不相同,值可以相同.若同时出现两个相同的键,则后 ...
- node-sass 安装失败
安装 npm install 时偶尔遇到报错:没有安装python或node-sass 安装失败的问题,百度之后发现是被墙了,但根据百度的方法换了淘宝镜像和用了vpn都安装失败, 原因可能是没有卸载之 ...
- Spring MVC_Hello World
[Hello World] 步骤: (1)加入jar包, (2)在web.xml中配置DispatcherServlet, (3)加入Spring MVC的配置文件, (4)编写处理请求的处理器,并标 ...
- 撸呀撸的左手(KMP+DP)
题目描述 撸呀撸很迷茫,因为他的左手总是不受控制,做一些不雅的事情.于是撸呀撸一狠心,决定戒撸.没想到,他的左手受不了寂寞,一闲下来就在键盘上各种乱敲. 唔,神奇的左手表示,safasfasaafaf ...