台阶问题

题目:

39级台阶,每步1或者2个台阶,必须是偶数步,求上台阶的方案数

解决思想:使用递归的思想。

代码:

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 
 6 namespace 阶¡Á梯¬Y
 7 {
 8     class Program
 9 {
10     //奇数
11         static int fun1(int n)
12         {
13             if (n == 1)
14                 return 1;
15             if (n == 2)
16                 return 1;
17             else
18                 return fun2(n - 1) + fun2(n - 2);
19         }
20         //偶数
21         static int fun2(int n)
22         {
23             if (n == 1)
24                 return 0;
25             if (n == 2)
26                 return 1;
27             else
28                 return fun1(n - 1) + fun1(n - 2);
29         }
30         static void Main(string[] args)
31         {
32             int n;
33             n = Convert.ToInt32(Console.ReadLine());
34             Console.WriteLine(fun2(n));
35             Console.ReadLine();
36         }
37     }
38 }
原文地址:https://www.cnblogs.com/lixiaokang-blog/p/7610628.html