{"id":2323,"date":"2022-01-24T10:05:59","date_gmt":"2022-01-24T02:05:59","guid":{"rendered":"http:\/\/139.9.1.231\/?p=2323"},"modified":"2022-01-24T10:06:00","modified_gmt":"2022-01-24T02:06:00","slug":"leetcodeday64","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2022\/01\/24\/leetcodeday64\/","title":{"rendered":"leetcodeday64 &#8211;\u6700\u5c0f\u8def\u5f84\u548c"},"content":{"rendered":"\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u5305\u542b\u975e\u8d1f\u6574\u6570\u7684&nbsp;<code><em>m<\/em>&nbsp;x&nbsp;<em>n<\/em><\/code>&nbsp;\u7f51\u683c&nbsp;<code>grid<\/code>&nbsp;\uff0c\u8bf7\u627e\u51fa\u4e00\u6761\u4ece\u5de6\u4e0a\u89d2\u5230\u53f3\u4e0b\u89d2\u7684\u8def\u5f84\uff0c\u4f7f\u5f97\u8def\u5f84\u4e0a\u7684\u6570\u5b57\u603b\u548c\u4e3a\u6700\u5c0f\u3002<\/p>\n\n\n\n<p><strong>\u8bf4\u660e\uff1a<\/strong>\u6bcf\u6b21\u53ea\u80fd\u5411\u4e0b\u6216\u8005\u5411\u53f3\u79fb\u52a8\u4e00\u6b65\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8f93\u5165\uff1a<\/strong>grid = &#91;&#91;1,3,1],&#91;1,5,1],&#91;4,2,1]]\n<strong>\u8f93\u51fa\uff1a<\/strong>7\n<strong>\u89e3\u91ca\uff1a<\/strong>\u56e0\u4e3a\u8def\u5f84 1\u21923\u21921\u21921\u21921 \u7684\u603b\u548c\u6700\u5c0f\u3002<\/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>grid = &#91;&#91;1,2,3],&#91;4,5,6]]\n<strong>\u8f93\u51fa\uff1a<\/strong>12<\/code><\/pre>\n\n\n\n<p><strong>\u63d0\u793a\uff1a<\/strong><\/p>\n\n\n\n<ul><li><code>m == grid.length<\/code><\/li><li><code>n == grid[i].length<\/code><\/li><li><code>1 &lt;= m, n &lt;= 200<\/code><\/li><li><code>0 &lt;= grid[i][j] &lt;= 100<\/code><\/li><\/ul>\n\n\n\n<p class=\"has-light-pink-background-color has-background\"><strong>\u601d\u8def\uff1a\u52a8\u6001\u89c4\u5212<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><img loading=\"lazy\" width=\"1024\" height=\"550\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-278-1024x550.png\" alt=\"\" class=\"wp-image-2325\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-278-1024x550.png 1024w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-278-300x161.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-278-768x413.png 768w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-278.png 1310w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code># @lc app=leetcode.cn id=64 lang=python3\r\n#\r\n# &#91;64] \u6700\u5c0f\u8def\u5f84\u548c\r\n#\r\n#\u52a8\u6001\u89c4\u5212 dp&#91;i]&#91;j]\u65f6\u5230i,j\u7684\u6700\u5c0f\u8def\u5f84\u548c\r\n# @lc code=start\r\nclass Solution:\r\n    def minPathSum(self, grid: List&#91;List&#91;int]]) -> int:\r\n        row = len(grid)\r\n        col = len(grid&#91;0])\r\n        dp=&#91;&#91;0]*col for i in range(row)]\r\n        for i in range(row):\r\n            for j in range(col):\r\n                if i == 0 and j!=0:\r\n                    dp&#91;i]&#91;j]=dp&#91;i]&#91;j-1]+grid&#91;i]&#91;j]\r\n                elif j == 0 and i!=0:\r\n                    dp&#91;i]&#91;j]=dp&#91;i-1]&#91;j]+grid&#91;i]&#91;j]\r\n                elif i==0 and j==0:\r\n                    dp&#91;i]&#91;j]=grid&#91;0]&#91;0]\r\n                else :\r\n                    dp&#91;i]&#91;j]=min(dp&#91;i-1]&#91;j],dp&#91;i]&#91;j-1])+grid&#91;i]&#91;j]\r\n        return dp&#91;row-1]&#91;col-1]<\/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-277.png\" alt=\"\" class=\"wp-image-2324\" width=\"523\" height=\"209\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-277.png 707w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-277-300x120.png 300w\" sizes=\"(max-width: 523px) 100vw, 523px\" \/><\/figure><\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7ed9\u5b9a\u4e00\u4e2a\u5305\u542b\u975e\u8d1f\u6574\u6570\u7684&nbsp;m&nbsp;x&nbsp;n&nbsp;\u7f51\u683c&nbsp;grid&#038;nbsp &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2022\/01\/24\/leetcodeday64\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">leetcodeday64 &#8211;\u6700\u5c0f\u8def\u5f84\u548c<\/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\/2323"}],"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=2323"}],"version-history":[{"count":3,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2323\/revisions"}],"predecessor-version":[{"id":2328,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2323\/revisions\/2328"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=2323"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=2323"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=2323"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}