{"id":2731,"date":"2023-10-17T11:53:35","date_gmt":"2023-10-17T03:53:35","guid":{"rendered":"https:\/\/white-night.club\/?p=2731"},"modified":"2023-11-09T11:07:48","modified_gmt":"2023-11-09T03:07:48","slug":"ad64","status":"publish","type":"post","link":"https:\/\/white-night.club\/index.php\/2023\/10\/17\/ad64\/","title":{"rendered":"\u6590\u6ce2\u90a3\u5951\u6570\u5217\uff1a\u9012\u5f52\u548c\u8bb0\u5fc6\u5316\u641c\u7d22"},"content":{"rendered":"\n<p>\u5728\u5b66\u4e60\u52a8\u6001\u89c4\u5212\u524d\uff0c\u9996\u5148\u5f97\u5bf9\u9012\u5f52\u6709\u4e00\u5b9a\u7684\u4e86\u89e3\u3002<\/p>\n\n\n\n<div style=\"height:60px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<blockquote class=\"wp-block-quote has-luminous-vivid-amber-color has-text-color\">\n<p>\u6590\u6ce2\u90a3\u5951\u6570\u5217<\/p>\n<cite><em>F(n)=F(n &#8211; 1)+F(n &#8211; 2) \uff08n\uff1e2\uff09<\/em><\/cite><\/blockquote>\n\n\n\n<p>\u6590\u6ce2\u90a3\u5951\u6570\u5217\u7684\u524d\u4e24\u9879\u4e3a1\u3002\u4ece\u7b2c\u4e09\u9879\u5f00\u59cb\uff0c\u6bcf\u4e00\u9879\u90fd\u7b49\u4e8e\u5b83\u7684\u524d\u4e24\u9879\u7684\u548c\u3002<\/p>\n\n\n\n<ul>\n<li>F(1)=1  F(2)=1<\/li>\n\n\n\n<li>F(3)=F(2)+F(1)=2<\/li>\n\n\n\n<li>F(4)=F(3)+F(2)=3<\/li>\n\n\n\n<li>&#8230;<\/li>\n\n\n\n<li>F(n)=F(n-1)+F(n-2)<\/li>\n<\/ul>\n\n\n\n<p>\u6709\u65f6\u5019\u8fd8\u4f1a\u51fa\u73b0F(0)\u7684\u60c5\u51b5\u3002\u4e0d\u8fc7F(0)=0\uff0c\u8fd8\u662f\u6bd4\u8f83\u597d\u5904\u7406\u7684\u3002<\/p>\n\n\n\n<div style=\"height:60px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<blockquote class=\"wp-block-quote has-luminous-vivid-amber-color has-text-color\">\n<p>\u9012\u5f52\u8ba1\u7b97\u6590\u6ce2\u90a3\u5951\u6570\u5217<\/p>\n<cite><em>C++\u5b9e\u73b0<\/em><\/cite><\/blockquote>\n\n\n\n<p>\u5982\u679c\u7528C++\u6c42\u6590\u6ce2\u90a3\u5951\uff0c\u4ee3\u7801\u5982\u4e0b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include&lt;iostream>\nusing namespace std;\n\nint fib(int n)\n{\n    if(n&lt;=1)\n    {\n        return n;\n    }\n    return fib(n-2)+fib(n-1);\n}\nint main()\n{\n    while(true)\n    {\n        int n;\n        cin>>n;\n        cout&lt;&lt;fib(n)&lt;&lt;endl;\n    }\n}<\/code><\/pre>\n\n\n\n<p>\u5176\u4e2d\uff0c\u9012\u5f52\u7684\u8fc7\u7a0b\u7c7b\u4f3c\u4e8e\u4e00\u4e2a\u4e8c\u53c9\u6811\u3002\u6bd4\u5982\u6c42F(4)\u65f6<\/p>\n\n\n\n<ul>\n<li>F(5)\u4e0d\u6ee1\u8db3n\uff1c2\uff0c\u8fd4\u56defib(4)+fib(3)<\/li>\n\n\n\n<li>F(4)\u548cF(3)\u90fd\u4e0d\u6ee1\u8db3\u6761\u4ef6\uff0c\u524d\u8005\u7ee7\u7eed\u8ba1\u7b97F(3)+F(2)\uff0c\u540e\u8005<mark style=\"background-color:rgba(0, 0, 0, 0);color:#fcb900\" class=\"has-inline-color\">\u8ba1\u7b97F(2)+F(1)<\/mark><\/li>\n\n\n\n<li>F(3)+F(2)\u8fd8\u662f\u4e0d\u6ee1\u8db3\u6761\u4ef6\uff0c<mark style=\"background-color:rgba(0, 0, 0, 0);color:#fcb900\" class=\"has-inline-color\">\u7ee7\u7eed\u8ba1\u7b97F(2)+F(1)<\/mark><\/li>\n<\/ul>\n\n\n\n<p>\u53ef\u4ee5\u770b\u5230\uff0cF(2)+F(1)\u88ab\u8ba1\u7b97\u4e86\u4e24\u6b21\u3002\u8fd9\u91cc\u5f15\u7528\u4e0bleetcode\u9898\u89e3\u4e2d\u7684\u56fe\u7247\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large has-custom-border\"><img decoding=\"async\" src=\"https:\/\/pic.leetcode-cn.com\/a6f819589ee5e50ec378f2c10835e9a510529bac44618444beb2202486062eee-image.png\" alt=\"\" style=\"border-style:none;border-width:0px;border-radius:0px\"\/><\/figure>\n\n\n\n<p>\u90a3\u4e48\u8fd9\u91cc\u5c31\u662f\u6211\u4eec\u4f18\u5316\u7684\u51fa\u53d1\u70b9\u4e86\u3002\u6211\u4eec\u53ef\u4ee5\u628a\u8ba1\u7b97\u8fc7\u7684\u7ed3\u679c\u50a8\u5b58\u8d77\u6765\uff0c\u5982\u679c\u5df2\u7ecf\u8ba1\u7b97\u8fc7\u4e86\u8be5\u9879\u7684F(n)\uff0c\u90a3\u4e48\u4e0b\u6b21\u8ba1\u7b97\u7684\u65f6\u5019\u76f4\u63a5\u7528\u5c31\u597d\u4e86\u3002<\/p>\n\n\n\n<p>\u8fd9\u79cd\u65b9\u6cd5\u53c8\u88ab\u53eb\u505a\u201c\u8bb0\u5fc6\u5316\u641c\u7d22\u201d\u3002\u56e0\u4e3a\u6bcf\u6b21\u5728\u8fd0\u7b97\u524d\u5b83\u4f1a\u5148\u6839\u636e\u201c\u8bb0\u5fc6\u201d\u53bb\u641c\u7d22\u4e4b\u524d\u662f\u5426\u6709\u8ba1\u7b97\u8fc7\u8be5\u503c\uff0c\u8ba1\u7b97\u8fc7\u5219\u76f4\u63a5\u8fd4\u56de\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include&lt;iostream>\r\n#include&lt;vector>\r\nusing namespace std;\r\n\r\nvector&lt;int>memo;\r\nint fib(int n)\r\n{\r\n    if(n&lt;=2)\r\n    {\r\n        return 1;\r\n    }\r\n    if(memo&#91;n]!=0)\r\n    {\r\n        return memo&#91;n];\r\n    }\r\n    memo&#91;n]=fib(n-2)+fib(n-1);\r\n    return memo&#91;n];\r\n}\r\nint main()\r\n{\r\n    while(true)\r\n    {\r\n        int n;\r\n        cin>>n;\r\n        memo.resize(n);\r\n        cout&lt;&lt;fib(n)&lt;&lt;endl;\r\n    }\r\n}<\/code><\/pre>\n\n\n\n<p>\u6211\u4e2a\u4eba\u611f\u89c9\u6709\u70b9\u50cf\u524d\u7f00\u548c\u3002\u524d\u7f00\u548c\u4e5f\u662f\u628a\u524dn\u9879\u548c\u7684\u7ed3\u679c\u5b58\u5230\u6570\u7ec4\u91cc\uff0c\u8981\u7684\u65f6\u5019\u5c31\u4ece\u6570\u7ec4\u91cc\u53d6\u3002\u53ea\u4e0d\u8fc7\u8bb0\u5fc6\u5316\u641c\u7d22\u662f\u76f8\u5f53\u4e8e\u9012\u5f52\u6765\u8bf4\u7684\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u901a\u8fc7\u6590\u6ce2\u90a3\u5951\u6570\u5217\u4e86\u89e3\u9012\u5f52\u4e0e\u8bb0\u5fc6\u5316\u641c\u7d22<\/p>\n","protected":false},"author":1,"featured_media":3220,"comment_status":"open","ping_status":"","sticky":false,"template":"base","format":"standard","meta":{"footnotes":""},"categories":[25,50],"tags":[36,101,100],"_links":{"self":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/2731"}],"collection":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/comments?post=2731"}],"version-history":[{"count":0,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/2731\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media\/3220"}],"wp:attachment":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media?parent=2731"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/categories?post=2731"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/tags?post=2731"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}