{"id":2302,"date":"2022-01-23T18:06:22","date_gmt":"2022-01-23T10:06:22","guid":{"rendered":"http:\/\/139.9.1.231\/?p=2302"},"modified":"2022-01-23T18:06:23","modified_gmt":"2022-01-23T10:06:23","slug":"leetcodeday62","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2022\/01\/23\/leetcodeday62\/","title":{"rendered":"leetcodeday62 &#8211;\u4e0d\u540c\u8def\u5f84"},"content":{"rendered":"\n<p>\u4e00\u4e2a\u673a\u5668\u4eba\u4f4d\u4e8e\u4e00\u4e2a&nbsp;<code>m x n<\/code>\u7f51\u683c\u7684\u5de6\u4e0a\u89d2 \uff08\u8d77\u59cb\u70b9\u5728\u4e0b\u56fe\u4e2d\u6807\u8bb0\u4e3a \u201cStart\u201d \uff09\u3002<\/p>\n\n\n\n<p>\u673a\u5668\u4eba\u6bcf\u6b21\u53ea\u80fd\u5411\u4e0b\u6216\u8005\u5411\u53f3\u79fb\u52a8\u4e00\u6b65\u3002\u673a\u5668\u4eba\u8bd5\u56fe\u8fbe\u5230\u7f51\u683c\u7684\u53f3\u4e0b\u89d2\uff08\u5728\u4e0b\u56fe\u4e2d\u6807\u8bb0\u4e3a \u201cFinish\u201d \uff09\u3002<\/p>\n\n\n\n<p>\u95ee\u603b\u5171\u6709\u591a\u5c11\u6761\u4e0d\u540c\u7684\u8def\u5f84\uff1f<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image is-style-default\"><img src=\"https:\/\/assets.leetcode.com\/uploads\/2018\/10\/22\/robot_maze.png\" alt=\"\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8f93\u5165\uff1a<\/strong>m = 3, n = 7\n<strong>\u8f93\u51fa\uff1a<\/strong>28<\/code><\/pre>\n\n\n\n<p><strong>\u793a\u4f8b 2\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8f93\u5165\uff1a<\/strong>m = 3, n = 2\n<strong>\u8f93\u51fa\uff1a<\/strong>3\n<strong>\u89e3\u91ca\uff1a<\/strong>\n\u4ece\u5de6\u4e0a\u89d2\u5f00\u59cb\uff0c\u603b\u5171\u6709 3 \u6761\u8def\u5f84\u53ef\u4ee5\u5230\u8fbe\u53f3\u4e0b\u89d2\u3002\n1. \u5411\u53f3 -&gt; \u5411\u4e0b -&gt; \u5411\u4e0b\n2. \u5411\u4e0b -&gt; \u5411\u4e0b -&gt; \u5411\u53f3\n3. \u5411\u4e0b -&gt; \u5411\u53f3 -&gt; \u5411\u4e0b<\/code><\/pre>\n\n\n\n<p class=\"has-light-pink-background-color has-background\">\u601d\u8def\uff1a\u5c06\u8be5\u95ee\u9898\u8f6c\u6362\u4e3a\uff1a\u8d70m-1  \u6b651\uff0c\u8d70n-1\u6b650\uff0c\u6240\u6709\u7684\u6392\u5217\u7ec4\u5408\uff1a<\/p>\n\n\n\n<p>\u5373 m-1 \u4e2aA\u548c n-1\u4e2aB\u7684\u6392\u5217\u7ec4\u5408\u6570\uff1a<\/p>\n\n\n\n<p>\u91c7\u7528\u63a8\u5bfc\u6cd5\uff1a\u5df2\u77e5 m-1 \u4e2aA\u548c n-1\u4e2aB\u7684\u6392\u5217\u7ec4\u5408\u6570 \uff0c\u90a3\u4e48\u6839\u636e m-1 \u4e2aA\u548c n-1\u4e2aB\u7684\u6392\u5217\u7ec4\u5408\u6570 \u63a8\u5bfcm\u4e2aA\uff0cn\u4e2aB\u7684\u6392\u5217\u7ec4\u5408\u6570\u3002<\/p>\n\n\n\n<p>(1) \u5f53\u6709m\u4e2aA\u548cn\u4e2aB\u65f6\uff0c\u603b\u7684\u6392\u5217\u6570\u4e3a(m+n)!\/m!\/n!;<\/p>\n\n\n\n<p>(2) \u7531\u4e8e\u4e0d\u77e5\u9053m\u548cn\u54ea\u4e2a\u5927\uff0c\u6545\u4e24\u4e2a\u503c\u90fd\u51cf1\uff0c\u6700\u540e\u77e5\u9053m\u548cn\u4e2d\u5176\u4e2d\u4e00\u4e2a\u4e3a0\uff1b<\/p>\n\n\n\n<p>(3) \u5f53\u6709m-1\u4e2aA\u548cn-1\u4e2aB\u65f6\uff0c\u603b\u7684\u6392\u5217\u6570\u4e3a(m+n-2)!\/(m-1)!\/(n-1)!;<\/p>\n\n\n\n<p>(4)\u8fd9\u6837\u4e24\u4e2a\u7684\u5173\u7cfb\u4e3a\uff1afun(m,n) = fun(m-1,n-1)<em>(m+n)<\/em>(m+n-1)\/m\/n;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># @lc app=leetcode.cn id=62 lang=python3\r\n#\r\n# &#91;62] \u4e0d\u540c\u8def\u5f84\r\n#\r\n\r\n# @lc code=start\r\nclass Solution:\r\n    def uniquePaths(self, m: int, n: int) -> int:\r\n        m=m-1\r\n        n=n-1\r\n        def subuniquePaths(m,n):\r\n            if m==0 or n==0:\r\n                return 1\r\n            else:\r\n                return int(subuniquePaths(m - 1 , n - 1)*(m + n)*(m+n-1)\/m\/n)\r\n        return subuniquePaths(m,n)<\/code><\/pre>\n\n\n\n<div class=\"wp-block-image is-style-default\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-274.png\" alt=\"\" class=\"wp-image-2307\" width=\"531\" height=\"164\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-274.png 788w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-274-300x93.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-274-768x239.png 768w\" sizes=\"(max-width: 531px) 100vw, 531px\" \/><\/figure><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u4e2a\u673a\u5668\u4eba\u4f4d\u4e8e\u4e00\u4e2a&nbsp;m x n\u7f51\u683c\u7684\u5de6\u4e0a\u89d2 \uff08\u8d77\u59cb\u70b9\u5728\u4e0b\u56fe\u4e2d\u6807\u8bb0\u4e3a \u201cStart\u201d \uff09\u3002 \u673a\u5668\u4eba\u6bcf\u6b21 &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2022\/01\/23\/leetcodeday62\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">leetcodeday62 &#8211;\u4e0d\u540c\u8def\u5f84<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[6],"tags":[],"_links":{"self":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2302"}],"collection":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/comments?post=2302"}],"version-history":[{"count":5,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2302\/revisions"}],"predecessor-version":[{"id":2308,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2302\/revisions\/2308"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=2302"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=2302"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=2302"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}