<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                **一. 題目描述** 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 3  3 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. **二. 題目分析** 與上一題Unique Paths類似,但要特別注意第一列的障礙。在上一題中,第一列全部是1,但是在這一題中不同的是,第一列如果某一行有障礙物,那么后面的行應該為0。 **三. 示例代碼** 使用動態規劃: ~~~ #include <iostream> #include <vector> using namespace std; class Solution { public: int uniquePathsWithObstacles(vector<vector<int> > &obstacleGrid) { const size_t x = obstacleGrid.size(); // 行數 const size_t y = obstacleGrid[0].size(); // 列數 vector<vector<int> > k; for (int i = 0; i < x; ++i) k.push_back(vector<int>(y, 0)); for (int i = 0; i < x; ++i) { if (obstacleGrid[i][0] == 0) k[i][0] = 1; else { for (int p = i; p < x; ++p) k[p][0] = 0; break; } } for (int j = 0; j < y; ++j) { if (obstacleGrid[0][j] == 0) k[0][j] = 1; else { for (int q = j; q < y; ++q) k[0][q] = 0; break; } } for (int i = 1; i < x; ++i) { for (int j = 1; j < y; ++j) { if (obstacleGrid[i][j] != 0) k[i][j] = 0; else k[i][j] = k[i - 1][j] + k[i][j - 1]; } } return k[x - 1][y - 1]; } }; ~~~ ![](https://box.kancloud.cn/2016-01-05_568bb5f047d5a.jpg) **四. 小結** [](http://blog.csdn.net/liyuefeilong/article/details/49520819#)[](http://blog.csdn.net/liyuefeilong/article/details/49520819# "分享到QQ空間")[](http://blog.csdn.net/liyuefeilong/article/details/49520819# "分享到新浪微博")[](http://blog.csdn.net/liyuefeilong/article/details/49520819# "分享到騰訊微博")[](http://blog.csdn.net/liyuefeilong/article/details/49520819# "分享到人人網")[](http://blog.csdn.net/liyuefeilong/article/details/49520819# "分享到微信")
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看