<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="zh-Hans-CN">
	<id>https://www.33dai.wiki/index.php?action=history&amp;feed=atom&amp;title=03-%E8%BF%9B%E9%98%B6%E5%9F%BA%E7%A1%80%2F05-%E9%80%92%E5%BD%92</id>
	<title>03-进阶基础/05-递归 - 版本历史</title>
	<link rel="self" type="application/atom+xml" href="https://www.33dai.wiki/index.php?action=history&amp;feed=atom&amp;title=03-%E8%BF%9B%E9%98%B6%E5%9F%BA%E7%A1%80%2F05-%E9%80%92%E5%BD%92"/>
	<link rel="alternate" type="text/html" href="https://www.33dai.wiki/index.php?title=03-%E8%BF%9B%E9%98%B6%E5%9F%BA%E7%A1%80/05-%E9%80%92%E5%BD%92&amp;action=history"/>
	<updated>2026-05-20T23:08:35Z</updated>
	<subtitle>本wiki上该页面的版本历史</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://www.33dai.wiki/index.php?title=03-%E8%BF%9B%E9%98%B6%E5%9F%BA%E7%A1%80/05-%E9%80%92%E5%BD%92&amp;diff=325&amp;oldid=prev</id>
		<title>33DAI：​导入1个版本</title>
		<link rel="alternate" type="text/html" href="https://www.33dai.wiki/index.php?title=03-%E8%BF%9B%E9%98%B6%E5%9F%BA%E7%A1%80/05-%E9%80%92%E5%BD%92&amp;diff=325&amp;oldid=prev"/>
		<updated>2026-05-20T18:12:09Z</updated>

		<summary type="html">&lt;p&gt;导入1个版本&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;zh-Hans-CN&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;←上一版本&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;2026年5月20日 (三) 18:12的版本&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;zh-Hans-CN&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;（没有差异）&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>33DAI</name></author>
	</entry>
	<entry>
		<id>https://www.33dai.wiki/index.php?title=03-%E8%BF%9B%E9%98%B6%E5%9F%BA%E7%A1%80/05-%E9%80%92%E5%BD%92&amp;diff=324&amp;oldid=prev</id>
		<title>-&gt;Importer：​批量导入三三文档</title>
		<link rel="alternate" type="text/html" href="https://www.33dai.wiki/index.php?title=03-%E8%BF%9B%E9%98%B6%E5%9F%BA%E7%A1%80/05-%E9%80%92%E5%BD%92&amp;diff=324&amp;oldid=prev"/>
		<updated>2026-05-20T16:50:33Z</updated>

		<summary type="html">&lt;p&gt;批量导入三三文档&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;zh-Hans-CN&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;←上一版本&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;2026年5月20日 (三) 16:50的版本&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;zh-Hans-CN&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;（没有差异）&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>-&gt;Importer</name></author>
	</entry>
	<entry>
		<id>https://www.33dai.wiki/index.php?title=03-%E8%BF%9B%E9%98%B6%E5%9F%BA%E7%A1%80/05-%E9%80%92%E5%BD%92&amp;diff=225&amp;oldid=prev</id>
		<title>33DAI：​导入1个版本</title>
		<link rel="alternate" type="text/html" href="https://www.33dai.wiki/index.php?title=03-%E8%BF%9B%E9%98%B6%E5%9F%BA%E7%A1%80/05-%E9%80%92%E5%BD%92&amp;diff=225&amp;oldid=prev"/>
		<updated>2026-05-20T16:25:20Z</updated>

		<summary type="html">&lt;p&gt;导入1个版本&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;zh-Hans-CN&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;←上一版本&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;2026年5月20日 (三) 16:25的版本&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;zh-Hans-CN&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;（没有差异）&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>33DAI</name></author>
	</entry>
	<entry>
		<id>https://www.33dai.wiki/index.php?title=03-%E8%BF%9B%E9%98%B6%E5%9F%BA%E7%A1%80/05-%E9%80%92%E5%BD%92&amp;diff=224&amp;oldid=prev</id>
		<title>-&gt;Importer：​批量导入三三文档</title>
		<link rel="alternate" type="text/html" href="https://www.33dai.wiki/index.php?title=03-%E8%BF%9B%E9%98%B6%E5%9F%BA%E7%A1%80/05-%E9%80%92%E5%BD%92&amp;diff=224&amp;oldid=prev"/>
		<updated>2026-05-20T16:22:29Z</updated>

		<summary type="html">&lt;p&gt;批量导入三三文档&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新页面&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;
== 简单递归 ==&lt;br /&gt;
&lt;br /&gt;
递归就是函数自己调用自己。&lt;br /&gt;
&lt;br /&gt;
=== 递归的两个要点 ===&lt;br /&gt;
&lt;br /&gt;
1. &amp;#039;&amp;#039;&amp;#039;边界条件&amp;#039;&amp;#039;&amp;#039;：何时停止递归&lt;br /&gt;
2. &amp;#039;&amp;#039;&amp;#039;递归关系&amp;#039;&amp;#039;&amp;#039;：如何用更小的问题表示当前问题&lt;br /&gt;
&lt;br /&gt;
=== 阶乘 ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;n! = n \times (n-1)!&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
int fact(int n)&lt;br /&gt;
{&lt;br /&gt;
    if (n == 0)        // 边界条件&lt;br /&gt;
        return 1;&lt;br /&gt;
    return n * fact(n - 1); // 递归关系&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 斐波那契数列 ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;F(1)=1,\ F(2)=1,\ F(n)=F(n-1)+F(n-2)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
int fib(int n)&lt;br /&gt;
{&lt;br /&gt;
    if (n &amp;lt;= 2)        // 边界条件&lt;br /&gt;
        return 1;&lt;br /&gt;
    return fib(n - 1) + fib(n - 2); // 递归关系&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
注意：纯递归求斐波那契数列效率很低 (&amp;lt;math&amp;gt;O(2^n)&amp;lt;/math&amp;gt;)，实际通常用递推。&lt;br /&gt;
&lt;br /&gt;
=== 递推 vs 递归 ===&lt;br /&gt;
&lt;br /&gt;
递推（循环实现，从下往上）：&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
int fib(int n)&lt;br /&gt;
{&lt;br /&gt;
    int a = 1, b = 1;&lt;br /&gt;
    for (int i = 3; i &amp;lt;= n; i++)&lt;br /&gt;
    {&lt;br /&gt;
        int c = a + b;&lt;br /&gt;
        a = b;&lt;br /&gt;
        b = c;&lt;br /&gt;
    }&lt;br /&gt;
    return b;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 递归实现全排列 ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
int n;&lt;br /&gt;
int a[10];&lt;br /&gt;
bool vis[10];&lt;br /&gt;
&lt;br /&gt;
void dfs(int step)&lt;br /&gt;
{&lt;br /&gt;
    if (step &amp;gt; n) // 边界：选完了&lt;br /&gt;
    {&lt;br /&gt;
        for (int i = 1; i &amp;lt;= n; i++)&lt;br /&gt;
            cout &amp;lt;&amp;lt; a[i] &amp;lt;&amp;lt; &amp;quot; &amp;quot;;&lt;br /&gt;
        cout &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
        return;&lt;br /&gt;
    }&lt;br /&gt;
    for (int i = 1; i &amp;lt;= n; i++)&lt;br /&gt;
    {&lt;br /&gt;
        if (!vis[i])&lt;br /&gt;
        {&lt;br /&gt;
            vis[i] = true;&lt;br /&gt;
            a[step] = i;&lt;br /&gt;
            dfs(step + 1);   // 递归选下一个&lt;br /&gt;
            vis[i] = false;  // 回溯&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 递归注意事项 ===&lt;br /&gt;
&lt;br /&gt;
- 递归深度过大可能导致&amp;#039;&amp;#039;&amp;#039;栈溢出&amp;#039;&amp;#039;&amp;#039;（Windows 默认约 &amp;lt;math&amp;gt;8&amp;lt;/math&amp;gt; MB，Linux 约 &amp;lt;math&amp;gt;8&amp;lt;/math&amp;gt; MB）&lt;br /&gt;
- 可以用 &amp;lt;code&amp;gt;ulimit -s unlimited&amp;lt;/code&amp;gt;（Linux）或开栈编译选项（Windows）增加栈空间&lt;br /&gt;
- 很多递归可以转化为递推来避免栈溢出&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:进阶基础]]&lt;br /&gt;
[[Category:三三文档]]&lt;/div&gt;</summary>
		<author><name>-&gt;Importer</name></author>
	</entry>
</feed>