{"id":2745,"date":"2023-10-17T16:39:04","date_gmt":"2023-10-17T08:39:04","guid":{"rendered":"https:\/\/white-night.club\/?p=2745"},"modified":"2023-11-09T11:07:48","modified_gmt":"2023-11-09T03:07:48","slug":"ad66","status":"publish","type":"post","link":"https:\/\/white-night.club\/index.php\/2023\/10\/17\/ad66\/","title":{"rendered":"LCR 126.\u00a0\u6590\u6ce2\u90a3\u5951\u6570"},"content":{"rendered":"\n<p><strong>\u6590\u6ce2\u90a3\u5951\u6570<\/strong>\u00a0\uff08\u901a\u5e38\u7528\u00a0<code>F(n)<\/code>\u00a0\u8868\u793a\uff09\u5f62\u6210\u7684\u5e8f\u5217\u79f0\u4e3a\u00a0<strong>\u6590\u6ce2\u90a3\u5951\u6570\u5217<\/strong>\u00a0\u3002\u8be5\u6570\u5217\u7531\u00a0<strong>0<\/strong>\u00a0\u548c\u00a0<strong>1<\/strong>\u00a0\u5f00\u59cb\uff0c\u540e\u9762\u7684\u6bcf\u4e00\u9879\u6570\u5b57\u90fd\u662f\u524d\u9762\u4e24\u9879\u6570\u5b57\u7684\u548c\u3002\u4e5f\u5c31\u662f\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">F(0) = 0\uff0cF(1) = 1\nF(n) = F(n - 1) + F(n - 2)\uff0c\u5176\u4e2d n &gt; 1\n<\/pre>\n\n\n\n<p>\u7ed9\u5b9a&nbsp;<code>n<\/code>&nbsp;\uff0c\u8bf7\u8ba1\u7b97&nbsp;<code>F(n)<\/code>&nbsp;\u3002<\/p>\n\n\n\n<p>\u7b54\u6848\u9700\u8981\u53d6\u6a21 1e9+7(1000000007) \uff0c\u5982\u8ba1\u7b97\u521d\u59cb\u7ed3\u679c\u4e3a\uff1a1000000008\uff0c\u8bf7\u8fd4\u56de 1\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>n = 2\n<strong>\u8f93\u51fa\uff1a<\/strong>1\n<strong>\u89e3\u91ca\uff1a<\/strong>F(2) = F(1) + F(0) = 1 + 0 = 1\n<\/pre>\n\n\n\n<p><strong>\u793a\u4f8b 2\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>n = 3\n<strong>\u8f93\u51fa\uff1a<\/strong>2\n<strong>\u89e3\u91ca\uff1a<\/strong>F(3) = F(2) + F(1) = 1 + 1 = 2\n<\/pre>\n\n\n\n<p><strong>\u793a\u4f8b 3\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>n = 4\n<strong>\u8f93\u51fa\uff1a<\/strong>3\n<strong>\u89e3\u91ca\uff1a<\/strong>F(4) = F(3) + F(2) = 2 + 1 = 3\n<\/pre>\n\n\n\n<p><strong>\u63d0\u793a\uff1a<\/strong><\/p>\n\n\n\n<ul>\n<li><code>0 &lt;= n &lt;= 100<\/code><\/li>\n<\/ul>\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>\u89e3\u9898\u601d\u8def<\/p>\n<cite><em>\u52a8\u6001\u89c4\u5212<\/em><\/cite><\/blockquote>\n\n\n\n<p>\u5177\u4f53\u7684\u5df2\u7ecf\u4e4b\u524d\u5df2\u7ecf\u63d0\u8fc7\u4e86\uff0c\u4ec0\u4e48\u9012\u5f52\u554a\u8bb0\u5fc6\u5316\u641c\u7d22\u90fd\u89e3\u91ca\u8fc7\u4e86\uff0c\u8fd9\u91cc\u5c31\u4e0d\u4f5c\u8fc7\u591a\u89e3\u91ca\u4e86\u3002<\/p>\n\n\n\n<p>\u4e0d\u8fc7\u8bb0\u5f97\u7ed3\u679c\u8981\u5bf91e9+7\u6c42\u4f59\u3002\u4f7f\u7ed3\u679c\u843d\u57281-1e9+7\u8fd9\u4e2a\u533a\u95f4\u5185\uff0c\u9632\u6b62\u5927\u6570\u6ea2\u51fa\u3002\u4e5f\u4e0d\u7528\u7ba1\u6590\u6ce2\u90a3\u5951\u6570\u5217\u8ba1\u7b97\u51fa\u6765\u7684\u7ed3\u679c\u6c42\u4f59\u4e0d\u5c31\u53d8\u4e86\u5417\u5565\u7684\uff0c\u522b\u4eba\u5c31\u662f\u4e3a\u4e86\u7528int\u63a5\u6536\u8d85\u51faint\u7c7b\u578b\u7684\u5927\u6570\u624d\u6c42\u7684\u4f59\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution {\r\npublic:\r\n    const int mod = 1e9 + 7;\r\n    int fib(int n) {\r\n        if (n &lt;= 1) {\r\n            return n;\r\n        }\r\n        int left=0,right=1;\r\n        int result=0;\r\n        for(int i=1;i&lt;n;i++)\r\n        {\r\n            result=(left+right)%mod;\r\n            left=right;\r\n            right=result;\r\n        }\r\n        return result;\r\n    }\r\n};\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Leetcode\u9898\u76ee\uff1a\u52a8\u6001\u89c4\u5212<\/p>\n","protected":false},"author":1,"featured_media":2827,"comment_status":"open","ping_status":"","sticky":false,"template":"base","format":"standard","meta":{"footnotes":""},"categories":[42,25],"tags":[38],"_links":{"self":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/2745"}],"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=2745"}],"version-history":[{"count":0,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/2745\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media\/2827"}],"wp:attachment":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media?parent=2745"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/categories?post=2745"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/tags?post=2745"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}