[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 ...
随机推荐
- cideogniter部署到阿里云服务器出现session加载错误
A PHP Error was encounteredSeverity: WarningMessage: mkdir() [function.mkdir]: Invalid argumentFilen ...
- POJ_2239_Selecting Courses
题意:一周上7天课,每天12节课,学校最多开设300节不同的课,每周每种课可以只有一个上课时间或者多个上课时间(上课内容一样),问一周最多可以选多少节课. 分析:二分图最大匹配,将一周84个时间点和可 ...
- 安卓app测试之启动时间和电量监控
一.启动时间监控 通过adb命令获取 adb shell am start -W /<packageName> /<activityName> 案例: adb shell am ...
- jmeter的webservice接口测试(SOAP/XML-RPC Request)
摘自:https://www.cnblogs.com/imyalost/p/5804359.html 项目背景:公司的微信端H5界面新开发了会员注册功能,需要对其进行压力测试 项目目标:需要承受每分钟 ...
- Linux System
Linux System linux 是一个功能强大的操作系统,同时它是一个自由软件,是免费的.源代码开放的,编制它的目的是建立不受任何商品化软件版权制约的.全世界都能自由使用的UNIX兼容产品.各种 ...
- Windows下运行jekyll,编码已不再是问题
很久没更新jekyll了,所以好奇着去官网看了下更新记录,发现如下更新条目(版本1.3.0/2013-11-04发布): Add encoding configuration option (#144 ...
- Effective C++标题整理
Effective C++ 话说光看这50个tip又有什么用呢?只有实际使用的时候才体现它们的价值才对. 就像只看<代码大全>不能成为一个好程序员,必须结合实际写项目经验才行. 从C转向C ...
- Linux 服务器 U盘安装(避免U盘启动)以及拔除U盘后无法引导系统
一.U盘制作 首先下载两个文件: · rhel-server-6.3-i386-boot.iso 启动镜像 · rhel-server-6.3-i386-dvd. ...
- JavaScript 面向对象的编程(二) 类的封装
类的定义 方式一 var Book = function(id, name, price){ //私有属性,外部不能直接访问 var num = 1; //私有方法, function checkId ...
- poj 1562 简单深搜
//搜八个方向即可 #include<stdio.h> #include<string.h> #define N 200 char ma[N][N]; int n,m,vis[ ...