Follow up for "Unique Paths":

Now consider if some obstacles are added to the grids. How many unique paths would there be?

An obstacle and empty space is marked as 1 and 0 respectively in the grid.

For example,

There is one obstacle in the middle of a 3x3 grid as illustrated below.

[
[0,0,0],
[0,1,0],
[0,0,0]
]

The total number of unique paths is 2.

Note: m and n will be at most 100.

代码:

class Solution {
public:
int uniquePathsWithObstacles(vector<vector<int> > &obstacleGrid) {
if(obstacleGrid.size()==) return ;
int row=obstacleGrid.size();
int col=obstacleGrid[].size();
int dp[][];
memset(dp,,sizeof(dp));
bool rblockTag=false;
bool cblockTag=false;
if(obstacleGrid[][]==||obstacleGrid[row-][col-]==)
return ;
for(int i=;i<col;++i){
if(obstacleGrid[][i]==) rblockTag=true;
if(!rblockTag) dp[][i]=;
else dp[][i]=;
}
for(int j=;j<row;++j){
if(obstacleGrid[j][]==) cblockTag=true;
if(!cblockTag) dp[j][]=;
else dp[j][]=;
}
for(int i=;i<row;++i){
for(int j=;j<col;++j){
if(obstacleGrid[i][j]==) dp[i][j]=;
else dp[i][j]=dp[i][j-]+dp[i-][j];//i和j是从1开始
}
}
return dp[row-][col-];
}
};

最新文章

  1. Tanks坦克大战
  2. Ubuntu 14.04 安装 JDK 8,ubuntu14.04
  3. ADF_Data Binding系列2_使用URL Service Data Control
  4. 免费下载:用于原型设计的 iOS 7 线框图
  5. IO流的练习2 —— 复制单级文件夹中的文件
  6. 关于Haproxy安装和配置:负载配置【haproxy.cfg】问题记录
  7. Storm安装与实验
  8. C++的双冒号(域解析符)
  9. 给Jquery添加alert,prompt方法,类似系统的Alert,Prompt,可以响应键盘,支持拖动
  10. Android 线程Thread的2种实现方法
  11. Java-Web监听器
  12. SQL Server自动化运维系列 - 监控磁盘剩余空间及SQL Server错误日志(Power Shell)
  13. 客户端禁用cookie情况下的URL重写
  14. javascript中事件对象注册与删除
  15. 关于jmeter读取CSV文件的详细设置
  16. collections 模块之Counter
  17. AngularJs创建一个带参数的自定义方法
  18. openstack vm ping 114.114.114.114
  19. Mac上 python 找不到 yaml模块
  20. linux实现开机自启动脚本

热门文章

  1. Java Web 开发中路径相关问题小结
  2. android应用流量信息提取
  3. IOS OS X 中集中消息的传递机制
  4. SQLite – GROUP BY
  5. project .mpp 查看当天工作任务 1.选择自己 2.选择起始和终止时间 就显示当天的任务了
  6. Kubernetes 架构(上)【转】
  7. Java数据结构和算法(四)--链表
  8. OPENCV3 命名空间等变化
  9. 爬虫学习之第一次获取网页内容及BeautifulSoup处理
  10. js&amp;jquery页面加载完执行