• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Uriel's Corner

            Research Associate @ Harvard University / Research Interests: Computer Vision, Biomedical Image Analysis, Machine Learning
            posts - 0, comments - 50, trackbacks - 0, articles - 594
            給出一個迷宮圖,格點值-1,0,1,2分別表示障礙、可走的格子、起點、終點,問起點到終點經過所有可走格子的路徑有幾條

            寫了個裸DFS,效率一般

            另有基于位運算和DP的解法,可以參考->https://leetcode.com/problems/unique-paths-iii/solutions/222466/python-bit-mask-dp-solution/

             1 #980
             2 #Runtime: 78 ms (Beats 54.24%)
             3 #Memory: 13.6 MB (Beats 23.73%)
             4 
             5 class Solution(object):
             6     def uniquePathsIII(self, grid):
             7         """
             8         :type grid: List[List[int]]
             9         :rtype: int
            10         """
            11         d = [[-1, 0], [1, 0], [0, 1], [0, -1]]
            12         m, n = len(grid), len(grid[0])
            13         self.ans = 0
            14 
            15         def DFS(x, y, vis, nonempty):
            16             if grid[x][y] == 2 and nonempty == -1:
            17                 self.ans += 1
            18                 return
            19             vis.add((x, y))
            20             for tx, ty in d:
            21                 if (x + tx, y + ty) not in vis and x + tx in range(m) and y + ty in range(n) and grid[x + tx][y + ty] != -1:
            22                     DFS(x + tx, y + ty, vis, nonempty - 1)
            23                     #vis[x + tx][y + ty] = 0
            24             vis.remove((x, y))
            25 
            26         nonempty = 0
            27         for x in range(len(grid)):
            28             for y in range(len(grid[0])):
            29                 if grid[x][y] == 1:
            30                     st_x, st_y = x, y
            31                 elif grid[x][y] == 0:
            32                     nonempty += 1
            33         DFS(st_x, st_y, set(), nonempty)
            34         return self.ans






            少妇熟女久久综合网色欲| 国产成人久久激情91| 久久久黄色大片| 7777久久久国产精品消防器材| 日韩乱码人妻无码中文字幕久久| 国产人久久人人人人爽| 91久久精品视频| 亚洲综合日韩久久成人AV| 久久综合丝袜日本网| 久久久精品国产免大香伊 | 99久久久国产精品免费无卡顿| 久久99亚洲网美利坚合众国| 狠狠色伊人久久精品综合网| 亚洲精品国产字幕久久不卡| 国产L精品国产亚洲区久久| 久久精品国产久精国产果冻传媒| 99久久成人国产精品免费| 亚洲欧美日韩精品久久亚洲区| AV色综合久久天堂AV色综合在| 精品综合久久久久久88小说| 91精品国产色综合久久| 亚洲国产日韩欧美综合久久| 国产91久久综合| 国产婷婷成人久久Av免费高清 | 欧美伊人久久大香线蕉综合| 国产一区二区精品久久| 亚洲狠狠婷婷综合久久久久| 亚洲国产日韩欧美综合久久| 久久久久久久国产免费看| 狠狠色丁香婷婷久久综合不卡| 亚洲级αV无码毛片久久精品| 青青草原综合久久大伊人导航| 狠狠狠色丁香婷婷综合久久五月| 久久婷婷五月综合国产尤物app | 久久精品这里热有精品| 亚洲中文字幕久久精品无码APP| 免费精品国产日韩热久久| 久久久久九国产精品| 人人狠狠综合88综合久久| 少妇久久久久久被弄到高潮 | 久久99精品久久只有精品|