• leetcode-unique paths 2


    The feeling of depending on oneself and AC is just great.

     1 #include <iostream>
     2 #include <vector>
     3 using namespace std;
     4 class Solution {
     5 public:
     6     int uniquePathsWithObstacles(vector<vector<int> > &obstacleGrid) {
     7         vector<vector<int>> d(obstacleGrid.size(), vector<int>(obstacleGrid[0].size(), 0));
     8         for (int i = 0; i < d.size(); i++)
     9         {
    10             if (obstacleGrid[i][0] != 1)
    11                 d[i][0] = 1;
    12             else break;
    13         }
    14         for (int i = 0; i < d[0].size(); i++)
    15         {
    16             if (obstacleGrid[0][i] != 1)
    17                 d[0][i] = 1;
    18             else break;
    19         }
    20         for (int i = 1; i < obstacleGrid.size(); i++)
    21         {
    22             for (int j = 1; j < obstacleGrid[i].size(); j++)
    23             {
    24                 if (obstacleGrid[i][j] != 1)///////////////////////////////////////
    25                 {
    26                     d[i][j] = d[i - 1][j] + d[i][j - 1];
    27                 }
    28                 //cout << d[i][j] << " ";
    29             }
    30             //cout << endl;
    31         }
    32         return d[obstacleGrid.size()-1][obstacleGrid[0].size()-1];
    33     }
    34 };
    35 int main()
    36 {
    37     Solution s;
    38     vector<vector<int>> obstacleGrid;
    39     int a0[] = { 0, 0, 0 };
    40     int a1[] = { 0, 1, 0 };
    41     int a2[] = { 0, 0, 0 };
    42     obstacleGrid.push_back(vector<int>(a0, a0 + 3));
    43     obstacleGrid.push_back(vector<int>(a1, a1 + 3));
    44     obstacleGrid.push_back(vector<int>(a2, a2 + 3));
    45 
    46     //print vector<vector<int>>
    47     //for (int i = 0; i < obstacleGrid.size(); i++)
    48     //{
    49     //    for (int j = 0; j < obstacleGrid[i].size(); j++)
    50     //    {
    51     //        cout << obstacleGrid[i][j]<<" ";
    52     //    }
    53     //    cout << endl;
    54     //}
    55     cout << s.uniquePathsWithObstacles(obstacleGrid) << endl;
    56     return 0;
    57 }
  • 相关阅读:
    android中的一个圆角图片
    android中一个评分的控件
    C++ primer(第五版)中需要复习第二遍的知识点记录
    在ubuntu18.04上交叉编译opencv2.4.9
    C6748和音频ADC连接时候的TDM以及I2S格式问题
    C6748的启动方式问题
    AK5703的ALC
    cool edit工具介绍及使用
    CCS编译环境及TI仿真器的使用
    把YUV转化成opencv中的Mat格式的两行代码备份
  • 原文地址:https://www.cnblogs.com/forcheryl/p/4001472.html
Copyright © 2020-2023  润新知