[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 ...
随机推荐
- C语言中结构体大小计算
1.普通结构体 struct student { char sex; char a; char b; int age; char name[100]; }; 该结构体大小为108 解答:1.先算str ...
- (转)淘淘商城系列——商品搜索功能Service实现
http://blog.csdn.net/column/details/15737.html 首先我们在taotao-search-interface工程中新建一个SearchService接口,并在 ...
- Django之auth登录认证
前言:我们在开发一个网站的时候,无可避免的需要设计实现网站的用户系统.此时我们需要实现包括用户注册.用户登录.用户认证.注销.修改密码等功能,这还真是个麻烦的事情呢. Django作为一个完美主义者的 ...
- eclipse配置Tomcat服务器server locations的方法
最近放弃了使用Myeclipse,转而使用eclipse作为开发工具,确实Myeclipse集成了太多东西,使得开发人员的配置越来越少,这不是个好事,使用eclipse后,有些地方就得自己去配置,比如 ...
- ThinkPHP---辅助方法
[三]Tp常见的辅助方法 原生SQL语句里除了目前所使用的基本操作增删改查,还有类似于group.where.order.limit等这样的字句. ThinkPHP封装了相应的子句方法:封装的方法都在 ...
- angular4打包以后,刷新报404
项目打包以后,上传到服务器,可以正常的切换页面,但是一旦刷新就会报404,找不到页面,其解决方法是:在app.module.ts里面引入下面的模块: import {HashLocationStrat ...
- 【计算几何】二维凸包——Graham's Scan法
凸包 点集Q的凸包(convex hull)是指一个最小凸多边形,满足Q中的点或者在多边形边上或者在其内.右图中由红色线段表示的多边形就是点集Q={p0,p1,...p12}的凸包. 一组平面上的点, ...
- 04StringBuffer相关知识、Arrays类、类型互换、正则、Date相关
04StringBuffer相关知识.Arrays类.类型互换.正则.Date相关-2018.7.12 1.StringBuffer A:StringBuffer的构造方法: public Strin ...
- python_ 学习笔记(运算符)
python的运算符基本和C语言一致,以下说一些不一样的! 算术运算符 **:代表乘方,对应也有**=: //:代表商向下取整,对应也有//=: 逻辑运算符 and or not 位运算符 :& ...
- python面向对象的特点,类定义等,私有属性、公有属性、成员属性
引子:类的对象在内存中的表示def dog(name,dog_type): def bark(d): print(d,'wang wang wang ...') data = { 'name':nam ...