{"id":1524,"date":"2026-05-16T09:38:02","date_gmt":"2026-05-16T01:38:02","guid":{"rendered":"http:\/\/wordpress.fangt.online\/?p=1524"},"modified":"2026-05-16T09:38:02","modified_gmt":"2026-05-16T01:38:02","slug":"%e7%ae%97%e6%b3%95%e5%a4%8d%e6%9d%82%e5%ba%a6%e6%a6%82%e5%bf%b5%e6%a2%b3%e7%90%86","status":"publish","type":"post","link":"http:\/\/wordpress.fangt.online\/index.php\/2026\/05\/16\/%e7%ae%97%e6%b3%95%e5%a4%8d%e6%9d%82%e5%ba%a6%e6%a6%82%e5%bf%b5%e6%a2%b3%e7%90%86\/","title":{"rendered":"\u7b97\u6cd5\u590d\u6742\u5ea6\u6982\u5ff5\u68b3\u7406"},"content":{"rendered":"\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e00\u3001\u57fa\u672c\u6982\u5ff5<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. \u5927O\u8868\u793a\u6cd5<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u8868\u793a<strong>\u6700\u574f\u60c5\u51b5<\/strong>\u4e0b\u7684\u589e\u957f\u7387\uff08\u5ffd\u7565\u5e38\u6570\u3001\u4f4e\u9636\u9879\uff09<\/li>\n\n\n\n<li>\u4f8b\uff1a( <math data-latex=\"T(n) = 3n^2 + 2n + 1 ) \u2192 ( O(n^2) \"><semantics><mrow><mi>T<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><mi>n<\/mi><mo form=\"postfix\" stretchy=\"false\">)<\/mo><mo>=<\/mo><mn>3<\/mn><msup><mi>n<\/mi><mn>2<\/mn><\/msup><mo>+<\/mo><mn>2<\/mn><mi>n<\/mi><mo>+<\/mo><mn>1<\/mn><mo form=\"postfix\" stretchy=\"false\">)<\/mo><mo stretchy=\"false\">\u2192<\/mo><mo form=\"prefix\" stretchy=\"false\">(<\/mo><mi>O<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><msup><mi>n<\/mi><mn>2<\/mn><\/msup><mo form=\"postfix\" stretchy=\"false\">)<\/mo><\/mrow><annotation encoding=\"application\/x-tex\">T(n) = 3n^2 + 2n + 1 ) \u2192 ( O(n^2) <\/annotation><\/semantics><\/math>)<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2. \u5e38\u89c1\u590d\u6742\u5ea6\uff08\u4ece\u5feb\u5230\u6162\uff09<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><math data-latex=\"O(1) < O(\\log n) < O(n) < O(n\\log n) < O(n^2) < O(2^n) < O(n!)\"><semantics><mrow><mi>O<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><mn>1<\/mn><mo form=\"postfix\" stretchy=\"false\">)<\/mo><mo>&lt;<\/mo><mi>O<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><mrow><mi>log<\/mi><mo>\u2061<\/mo><mspace width=\"0.1667em\"><\/mspace><\/mrow><mi>n<\/mi><mo form=\"postfix\" stretchy=\"false\">)<\/mo><mo>&lt;<\/mo><mi>O<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><mi>n<\/mi><mo form=\"postfix\" stretchy=\"false\">)<\/mo><mo>&lt;<\/mo><mi>O<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><mi>n<\/mi><mrow><mspace width=\"0.1667em\"><\/mspace><mi>log<\/mi><mo>\u2061<\/mo><mspace width=\"0.1667em\"><\/mspace><\/mrow><mi>n<\/mi><mo form=\"postfix\" stretchy=\"false\">)<\/mo><mo>&lt;<\/mo><mi>O<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><msup><mi>n<\/mi><mn>2<\/mn><\/msup><mo form=\"postfix\" stretchy=\"false\">)<\/mo><mo>&lt;<\/mo><mi>O<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><msup><mn>2<\/mn><mi>n<\/mi><\/msup><mo form=\"postfix\" stretchy=\"false\">)<\/mo><mo>&lt;<\/mo><mi>O<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><mi>n<\/mi><mo form=\"postfix\" stretchy=\"false\">!<\/mo><mo form=\"postfix\" stretchy=\"false\">)<\/mo><\/mrow><annotation encoding=\"application\/x-tex\">O(1) &lt; O(\\log n) &lt; O(n) &lt; O(n\\log n) &lt; O(n^2) &lt; O(2^n) &lt; O(n!)<\/annotation><\/semantics><\/math><\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e8c\u3001\u591a\u9879\u5f0f\u590d\u6742\u5ea6<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. (<math data-latex=\" O(1) \"><semantics><mrow><mi>O<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><mn>1<\/mn><mo form=\"postfix\" stretchy=\"false\">)<\/mo><\/mrow><annotation encoding=\"application\/x-tex\"> O(1) <\/annotation><\/semantics><\/math>) \u2014\u2014 \u5e38\u6570\u65f6\u95f4<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u7279\u5f81<\/strong>\uff1a\u6267\u884c\u6b21\u6570\u4e0e\u8f93\u5165\u89c4\u6a21 n \u65e0\u5173<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u4ee3\u7801\u7ed3\u6784<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int a = arr&#91;0];           \/\/ \u4e00\u6b21\u64cd\u4f5c\nint b = a * 2 + 5;        \/\/ \u51e0\u6b21\u8fd0\u7b97\uff0c\u4ecd O(1)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2. (<math data-latex=\" O(n)\"><semantics><mrow><mi>O<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><mi>n<\/mi><mo form=\"postfix\" stretchy=\"false\">)<\/mo><\/mrow><annotation encoding=\"application\/x-tex\"> O(n)<\/annotation><\/semantics><\/math>) \u2014\u2014 \u7ebf\u6027\u65f6\u95f4<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u7279\u5f81<\/strong>\uff1a\u5355\u5c42\u5faa\u73af\uff0c\u5faa\u73af\u6b21\u6570\u4e0e n \u6210\u6b63\u6bd4<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u4ee3\u7801\u7ed3\u6784<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>for(int i = 0; i &lt; n; i++) {\n    \/\/ O(1) \u64cd\u4f5c\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3. (<math data-latex=\"O(n^2) \"><semantics><mrow><mi>O<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><msup><mi>n<\/mi><mn>2<\/mn><\/msup><mo form=\"postfix\" stretchy=\"false\">)<\/mo><\/mrow><annotation encoding=\"application\/x-tex\">O(n^2) <\/annotation><\/semantics><\/math>) \u2014\u2014 \u5e73\u65b9\u65f6\u95f4<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u7279\u5f81<\/strong>\uff1a\u53cc\u91cd\u5faa\u73af\uff0c\u5185\u5916\u90fd\u4e0e n \u76f8\u5173<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u4ee3\u7801\u7ed3\u6784<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>for(int i = 0; i &lt; n; i++) {\n    for(int j = 0; j &lt; n; j++) {\n        \/\/ O(1) \u64cd\u4f5c\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u53d8\u4f53<\/strong>\uff08\u4ecd\u662f (<math data-latex=\"O(n^2)\"><semantics><mrow><mi>O<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><msup><mi>n<\/mi><mn>2<\/mn><\/msup><mo form=\"postfix\" stretchy=\"false\">)<\/mo><\/mrow><annotation encoding=\"application\/x-tex\">O(n^2)<\/annotation><\/semantics><\/math>)\uff09\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>for(int i = 0; i &lt; n; i++) {\n    for(int j = i; j &lt; n; j++) {  \/\/ \u7ea6 n\u00b2\/2 \u6b21\n        \/\/ ...\n    }\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">4. (<math data-latex=\" O(n^3) \"><semantics><mrow><mi>O<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><msup><mi>n<\/mi><mn>3<\/mn><\/msup><mo form=\"postfix\" stretchy=\"false\">)<\/mo><\/mrow><annotation encoding=\"application\/x-tex\"> O(n^3) <\/annotation><\/semantics><\/math>) \u2014\u2014 \u7acb\u65b9\u65f6\u95f4<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u7279\u5f81<\/strong>\uff1a\u4e09\u91cd\u5faa\u73af<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>for(int i = 0; i &lt; n; i++)\n    for(int j = 0; j &lt; n; j++)\n        for(int k = 0; k &lt; n; k++)\n            \/\/ O(1)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">5. \u591a\u9879\u5f0f\u590d\u6742\u5ea6\u7684<strong>\u52a0\u6cd5 vs \u4e58\u6cd5<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u987a\u5e8f\u6267\u884c<\/strong>\uff1a(<math data-latex=\"O(n) + O(n^2) = O(n^2) \"><semantics><mrow><mi>O<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><mi>n<\/mi><mo form=\"postfix\" stretchy=\"false\">)<\/mo><mo>+<\/mo><mi>O<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><msup><mi>n<\/mi><mn>2<\/mn><\/msup><mo form=\"postfix\" stretchy=\"false\">)<\/mo><mo>=<\/mo><mi>O<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><msup><mi>n<\/mi><mn>2<\/mn><\/msup><mo form=\"postfix\" stretchy=\"false\">)<\/mo><\/mrow><annotation encoding=\"application\/x-tex\">O(n) + O(n^2) = O(n^2) <\/annotation><\/semantics><\/math>)\uff08\u53d6\u6700\u9ad8\u9636\uff09<\/li>\n\n\n\n<li><strong>\u5d4c\u5957\u6267\u884c<\/strong>\uff1a(<math data-latex=\"O(n) \\times O(n) = O(n^2)\"><semantics><mrow><mi>O<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><mi>n<\/mi><mo form=\"postfix\" stretchy=\"false\">)<\/mo><mo>\u00d7<\/mo><mi>O<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><mi>n<\/mi><mo form=\"postfix\" stretchy=\"false\">)<\/mo><mo>=<\/mo><mi>O<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><msup><mi>n<\/mi><mn>2<\/mn><\/msup><mo form=\"postfix\" stretchy=\"false\">)<\/mo><\/mrow><annotation encoding=\"application\/x-tex\">O(n) \\times O(n) = O(n^2)<\/annotation><\/semantics><\/math>)<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e09\u3001\u5bf9\u6570\u590d\u6742\u5ea6 (<math data-latex=\" O(\\log n) \"><semantics><mrow><mi>O<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><mrow><mi>log<\/mi><mo>\u2061<\/mo><mspace width=\"0.1667em\"><\/mspace><\/mrow><mi>n<\/mi><mo form=\"postfix\" stretchy=\"false\">)<\/mo><\/mrow><annotation encoding=\"application\/x-tex\"> O(\\log n) <\/annotation><\/semantics><\/math>)<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u7279\u5f81<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6bcf\u6b21\u5faa\u73af\u5c06\u95ee\u9898\u89c4\u6a21<strong>\u51cf\u534a<\/strong>\uff08\u6216\u53d8\u4e3a\u56fa\u5b9a\u6bd4\u4f8b\uff09<\/li>\n\n\n\n<li>\u5e38\u89c1\u4e8e\u4e8c\u5206\u6cd5\u3001\u500d\u589e\u6cd5<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u4ee3\u7801\u7ed3\u6784 1\uff1a\u5faa\u73af\u9664\u4ee5 2<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>int i = n;\nwhile(i &gt; 0) {\n    \/\/ O(1) \u64cd\u4f5c\n    i \/= 2;          \/\/ \u5173\u952e\uff1a\u6bcf\u6b21\u51cf\u534a\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5206\u6790<\/strong>\uff1an \u2192 n\/2 \u2192 n\/4 \u2192 \u2026 \u2192 1\uff0c\u5171 (<math data-latex=\" \\log_2 n \"><semantics><mrow><msub><mi>log<\/mi><mn>2<\/mn><\/msub><mo>\u2061<\/mo><mspace width=\"0.1667em\"><\/mspace><mi>n<\/mi><\/mrow><annotation encoding=\"application\/x-tex\"> \\log_2 n <\/annotation><\/semantics><\/math>) \u6b65<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u4ee3\u7801\u7ed3\u6784 2\uff1a\u5faa\u73af\u4e58\u4ee5 2<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>for(int i = 1; i &lt; n; i *= 2) {\n    \/\/ O(1) \u64cd\u4f5c\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5206\u6790<\/strong>\uff1a1, 2, 4, 8, \u2026, \u5171 (<math data-latex=\" \\log_2 n\"><semantics><mrow><msub><mi>log<\/mi><mn>2<\/mn><\/msub><mo>\u2061<\/mo><mspace width=\"0.1667em\"><\/mspace><mi>n<\/mi><\/mrow><annotation encoding=\"application\/x-tex\"> \\log_2 n<\/annotation><\/semantics><\/math>) \u6b65<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u4ee3\u7801\u7ed3\u6784 3\uff1a\u4e8c\u5206\u67e5\u627e<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>int l = 0, r = n-1;\nwhile(l &lt;= r) {\n    int mid = (l+r)\/2;\n    if(arr&#91;mid] == target) return mid;\n    else if(arr&#91;mid] &lt; target) l = mid+1;\n    else r = mid-1;\n}<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u56db\u3001(<math data-latex=\" O(n \\log n) \"><semantics><mrow><mi>O<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><mi>n<\/mi><mrow><mspace width=\"0.1667em\"><\/mspace><mi>log<\/mi><mo>\u2061<\/mo><mspace width=\"0.1667em\"><\/mspace><\/mrow><mi>n<\/mi><mo form=\"postfix\" stretchy=\"false\">)<\/mo><\/mrow><annotation encoding=\"application\/x-tex\"> O(n \\log n) <\/annotation><\/semantics><\/math>) \u590d\u6742\u5ea6<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u7279\u5f81<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5916\u5c42\u7ebf\u6027\uff0c\u5185\u5c42\u5bf9\u6570<\/li>\n\n\n\n<li>\u6216\u5206\u6cbb\u7b97\u6cd5\uff08\u5f52\u5e76\u6392\u5e8f\u3001\u5feb\u901f\u6392\u5e8f\u7684\u671f\u671b\uff09<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u4ee3\u7801\u7ed3\u6784 1\uff1an \u00d7 log n<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>for(int i = 0; i &lt; n; i++) {      \/\/ O(n)\n    int j = n;\n    while(j &gt; 0) {                \/\/ O(log n)\n        \/\/ O(1)\n        j \/= 2;\n    }\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u4ee3\u7801\u7ed3\u6784 2\uff1a\u57c3\u6c0f\u7b5b<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>bool isPrime&#91;n+1];\nfill(isPrime, isPrime+n+1, true);\nfor(int i = 2; i &lt;= sqrt(n); i++) {     \/\/ \u5916\u5c42 ~\u221an\n    if(isPrime&#91;i]) {\n        for(int j = i*i; j &lt;= n; j += i) {  \/\/ \u5185\u5c42\u603b\u6b21\u6570 ~ n log log n\n            isPrime&#91;j] = false;\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u590d\u6742\u5ea6<\/strong>\uff1a( <math data-latex=\"O(n \\log \\log n)\"><semantics><mrow><mi>O<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><mi>n<\/mi><mrow><mspace width=\"0.1667em\"><\/mspace><mi>log<\/mi><mo>\u2061<\/mo><mspace width=\"0.1667em\"><\/mspace><\/mrow><mrow><mi>log<\/mi><mo>\u2061<\/mo><mspace width=\"0.1667em\"><\/mspace><\/mrow><mi>n<\/mi><mo form=\"postfix\" stretchy=\"false\">)<\/mo><\/mrow><annotation encoding=\"application\/x-tex\">O(n \\log \\log n)<\/annotation><\/semantics><\/math> ) \u2014\u2014 \u5c5e\u4e8e ( <math data-latex=\"O(n \\log n)\"><semantics><mrow><mi>O<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><mi>n<\/mi><mrow><mspace width=\"0.1667em\"><\/mspace><mi>log<\/mi><mo>\u2061<\/mo><mspace width=\"0.1667em\"><\/mspace><\/mrow><mi>n<\/mi><mo form=\"postfix\" stretchy=\"false\">)<\/mo><\/mrow><annotation encoding=\"application\/x-tex\">O(n \\log n)<\/annotation><\/semantics><\/math> ) \u7ea7\u522b<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u4ee3\u7801\u7ed3\u6784 3\uff1a\u5f52\u5e76\u6392\u5e8f<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u6bcf\u6b21\u5206\u4e24\u534a\uff0c\u6df1\u5ea6 (<math data-latex=\" \\log n \"><semantics><mrow><mrow><mi>log<\/mi><mo>\u2061<\/mo><mspace width=\"0.1667em\"><\/mspace><\/mrow><mi>n<\/mi><\/mrow><annotation encoding=\"application\/x-tex\"> \\log n <\/annotation><\/semantics><\/math>)\uff0c\u6bcf\u5c42\u5408\u5e76 ( <math data-latex=\"O(n)\"><semantics><mrow><mi>O<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><mi>n<\/mi><mo form=\"postfix\" stretchy=\"false\">)<\/mo><\/mrow><annotation encoding=\"application\/x-tex\">O(n)<\/annotation><\/semantics><\/math> )\uff0c\u603b ( <math data-latex=\"O(n \\log n)\"><semantics><mrow><mi>O<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><mi>n<\/mi><mrow><mspace width=\"0.1667em\"><\/mspace><mi>log<\/mi><mo>\u2061<\/mo><mspace width=\"0.1667em\"><\/mspace><\/mrow><mi>n<\/mi><mo form=\"postfix\" stretchy=\"false\">)<\/mo><\/mrow><annotation encoding=\"application\/x-tex\">O(n \\log n)<\/annotation><\/semantics><\/math> )<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e94\u3001\u6307\u6570\u590d\u6742\u5ea6 ( <math data-latex=\"O(2^n)\"><semantics><mrow><mi>O<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><msup><mn>2<\/mn><mi>n<\/mi><\/msup><mo form=\"postfix\" stretchy=\"false\">)<\/mo><\/mrow><annotation encoding=\"application\/x-tex\">O(2^n)<\/annotation><\/semantics><\/math> )<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u7279\u5f81<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6bcf\u5c42\u9012\u5f52\u5206\u6210\u4e24\u4e2a\u5b50\u95ee\u9898<\/li>\n\n\n\n<li>\u5e38\u89c1\u4e8e\u66b4\u529b\u641c\u7d22\u3001\u9012\u5f52\u679a\u4e3e\u5b50\u96c6<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u4ee3\u7801\u7ed3\u6784\uff1a\u9012\u5f52\u679a\u4e3e\u5b50\u96c6<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>void dfs(int idx, int n) {\n    if(idx == n) return;\n    \/\/ \u9009\u6216\u4e0d\u9009\u4e24\u79cd\u9009\u62e9\n    dfs(idx+1, n);   \/\/ \u4e0d\u9009\n    dfs(idx+1, n);   \/\/ \u9009\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8c03\u7528\u6b21\u6570\uff1a(<math data-latex=\"2^n \"><semantics><msup><mn>2<\/mn><mi>n<\/mi><\/msup><annotation encoding=\"application\/x-tex\">2^n <\/annotation><\/semantics><\/math>)<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u53e6\u4e00\u79cd\uff1a\u6590\u6ce2\u90a3\u5951\u9012\u5f52\uff08\u672a\u4f18\u5316\uff09<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>int fib(int n) {\n    if(n &lt;= 1) return n;\n    return fib(n-1) + fib(n-2);  \/\/ \u4e24\u4e2a\u9012\u5f52\u8c03\u7528\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u590d\u6742\u5ea6 ( <math data-latex=\"O(2^n)\"><semantics><mrow><mi>O<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><msup><mn>2<\/mn><mi>n<\/mi><\/msup><mo form=\"postfix\" stretchy=\"false\">)<\/mo><\/mrow><annotation encoding=\"application\/x-tex\">O(2^n)<\/annotation><\/semantics><\/math> )\uff08\u5b9e\u9645\u7ea6 ( <math data-latex=\"\\phi^n\"><semantics><msup><mi>\u03d5<\/mi><mi>n<\/mi><\/msup><annotation encoding=\"application\/x-tex\">\\phi^n<\/annotation><\/semantics><\/math> )\uff0c\u4ee51.618\u4e3a\u5e95\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u57fa\u672c\u6982\u5ff5 1. \u5927O\u8868\u793a\u6cd5 2. \u5e38\u89c1\u590d\u6742\u5ea6\uff08\u4ece\u5feb\u5230\u6162\uff09 \u4e8c\u3001\u591a\u9879\u5f0f\u590d\u6742\u5ea6 1. (O(1) O(1) ) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[61],"tags":[],"class_list":["post-1524","post","type-post","status-publish","format-standard","hentry","category-zl"],"_links":{"self":[{"href":"http:\/\/wordpress.fangt.online\/index.php\/wp-json\/wp\/v2\/posts\/1524","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/wordpress.fangt.online\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/wordpress.fangt.online\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/wordpress.fangt.online\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/wordpress.fangt.online\/index.php\/wp-json\/wp\/v2\/comments?post=1524"}],"version-history":[{"count":1,"href":"http:\/\/wordpress.fangt.online\/index.php\/wp-json\/wp\/v2\/posts\/1524\/revisions"}],"predecessor-version":[{"id":1525,"href":"http:\/\/wordpress.fangt.online\/index.php\/wp-json\/wp\/v2\/posts\/1524\/revisions\/1525"}],"wp:attachment":[{"href":"http:\/\/wordpress.fangt.online\/index.php\/wp-json\/wp\/v2\/media?parent=1524"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/wordpress.fangt.online\/index.php\/wp-json\/wp\/v2\/categories?post=1524"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/wordpress.fangt.online\/index.php\/wp-json\/wp\/v2\/tags?post=1524"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}