[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 ...
随机推荐
- github与git常用的一些基本配置与命令
首次Git设置:ssh-keygen -t ras -C "email@xxx" 生成SSH (共钥)将生成的SSH key复制到文本框中即可(title默认为邮箱名) 你的身份( ...
- Java中PrintStream(打印输出流)
Java中PrintStream(打印输出流) PrintStream 是打印输出流,它继承于FilterOutputStream. PrintStream 是用来装饰其它输出流.它能为其他输出流 ...
- Modbus测试工具ModbusPoll与Modbus Slave使用方法
感谢https://blog.csdn.net/byxdaz/article/details/77979114原创,由于CSDN经常调整,故再编辑收藏,并修改了部分BUG. 一.介绍 Modbus P ...
- jstree的基本应用----记录
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- .net core Elasticsearch 查询更新
记录一下: 数据结构如下: public class ESUserTransaction { public long AccountId { get; set; } public string Var ...
- 浅谈:nodejs在cmd提示不是内部或外部命令
今天用cmd安装个库,结果发现node不是内部命令,检查后发现上次重装nodejs换了个安装位置,path环境变量忘改了. 找到变量值中node的安装地址,比如C:develop\nodejs,如果不 ...
- 14XML解析
XML解析 XML解析 DOM4J DOM4J是dom4j.org出品的一个开源XML解析包Dom4j是一个易用的.开源的库,用于XML,XPath和XSLT的解析及相关应用.它应用于Java平台,采 ...
- jenkins自动部署测试环境
构建脚本如下: echo "当前目录":$(pwd)echo "当前时间":$(date +%Y-%m-%d_%H:%M)find ./ -type f -na ...
- Linux kernel-汇编基础
mov ASSEMABLE C LANGUAGE movl %eax,%edx edx = eax; --->register mode movl $0x123,%edx edx = 0x123 ...
- C++ map使用总结
0. Backgroud 此文章源于博主(sunshinewave),转到自己博客以后方便查看 map是STL的一个关联容器,它提供一对一(其中第一个可以称为关键字,每个关键字只能在map中出现一次, ...