{"id":684,"date":"2020-06-22T14:57:43","date_gmt":"2020-06-22T06:57:43","guid":{"rendered":"http:\/\/www.guanhaobo.cn\/?p=684"},"modified":"2020-06-22T14:57:43","modified_gmt":"2020-06-22T06:57:43","slug":"jz7-%e6%96%90%e6%b3%a2%e9%82%a3%e5%a5%91%e6%95%b0%e5%88%97","status":"publish","type":"post","link":"https:\/\/www.guanhaobo.cn\/?p=684","title":{"rendered":"JZ7 \u2014 \u6590\u6ce2\u90a3\u5951\u6570\u5217"},"content":{"rendered":"<h3>\u9898\u76ee\u63cf\u8ff0<\/h3>\n<p>\u5927\u5bb6\u90fd\u77e5\u9053\u6590\u6ce2\u90a3\u5951\u6570\u5217\uff0c\u73b0\u5728\u8981\u6c42\u8f93\u5165\u4e00\u4e2a\u6574\u6570n\uff0c\u8bf7\u4f60\u8f93\u51fa\u6590\u6ce2\u90a3\u5951\u6570\u5217\u7684\u7b2cn\u9879\uff08\u4ece0\u5f00\u59cb\uff0c\u7b2c0\u9879\u4e3a0\uff0c\u7b2c1\u9879\u662f1\uff09\u3002<br \/>\nn&lt;=39<\/p>\n<h3>\u9898\u76ee\u5206\u6790<\/h3>\n<p>\u6590\u6ce2\u90a3\u5951\u6570\u5217\u7684\u6570\u5b66\u89c4\u5f8b\u662f<code>f[n] = f[n-1] + f[n-2]<\/code><\/p>\n<h3>\u52a8\u6001\u89c4\u5212<\/h3>\n<p>\u4ece\u524d\u5411\u540e\u9012\u63a8\u5373\u53ef\u3002<\/p>\n<h5>C++<\/h5>\n<pre><code class=\"language-cpp line-numbers\">class Solution\n{\npublic:\n    int Fibonacci(int n)\n    {\n        int ans[50] = {0, 1};\n        for (int i = 2; i &lt;= n; i++)\n            ans[i] = ans[i - 1] + ans[i - 2];\n        return ans[n];\n    }\n};\n<\/code><\/pre>\n<h5>Java<\/h5>\n<pre><code class=\"language-Java line-numbers\">class Solution {\n    public int Fibonacci(int n) {\n        int[] ans = new int[50];\n        ans[0] = 0;\n        ans[1] = 1;\n        for (int i = 2; i &lt;= n; i++)\n            ans[i] = ans[i - 1] + ans[i - 2];\n        return ans[n];\n    }\n}\n<\/code><\/pre>\n<h3>\u8bb0\u5fc6\u5316\u9012\u5f52<\/h3>\n<p>\u4ece\u540e\u5411\u524d\u9012\u5f52\uff0c\u5c06\u7ed3\u679c\u4fdd\u5b58\u4e0b\u6765\uff0c\u4fbf\u4e8e\u590d\u7528\uff0c\u8282\u7701\u9012\u5f52\u65f6\u95f4\u3002<\/p>\n<h5>C++<\/h5>\n<pre><code class=\"language-cpp line-numbers\">class Solution\n{\npublic:\n    Solution()\n    {\n        memset(ans, 0, sizeof(ans));\n    }\n    int Fibonacci(int n)\n    {\n        if (n == 0)\n            return 0;\n        if (n == 1)\n            return 1;\n        if (ans[n] == 0)\n            ans[n] = Fibonacci(n - 1) + Fibonacci(n - 2);\n        return ans[n];\n    }\n\nprivate:\n    int ans[50];\n};\n<\/code><\/pre>\n<h5>Java<\/h5>\n<pre><code class=\"language-java line-numbers\">public class Solution {\n    private int[] ans = new int[50];\n\n    public int Fibonacci(int n) {\n        if (n == 0)\n            return 0;\n        if (n == 1)\n            return 1;\n        if (ans[n] == 0)\n            ans[n] = Fibonacci(n - 1) + Fibonacci(n - 2);\n        return ans[n];\n    }\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u9898\u76ee\u63cf\u8ff0 \u5927\u5bb6\u90fd\u77e5\u9053\u6590\u6ce2\u90a3\u5951\u6570\u5217\uff0c\u73b0\u5728\u8981\u6c42\u8f93\u5165\u4e00\u4e2a\u6574\u6570n\uff0c\u8bf7\u4f60\u8f93\u51fa\u6590\u6ce2\u90a3\u5951\u6570\u5217\u7684\u7b2cn\u9879\uff08\u4ece0\u5f00\u59cb\uff0c\u7b2c0\u9879\u4e3a0\uff0c [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[39],"class_list":["post-684","post","type-post","status-publish","format-standard","hentry","category-algo","tag-offer"],"_links":{"self":[{"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/posts\/684","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=684"}],"version-history":[{"count":0,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/posts\/684\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=684"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=684"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=684"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}