/*
* 一个人上楼梯 可以有两种方式 ‘一次上一阶’和‘一次上两阶’
* 问题: 有一个10阶的楼梯 他有几种方式上去?
* 补充: 如果楼梯是1阶,他有一种上法(一次上一阶);如果楼梯是两阶他有2中上法(一次上一阶上2次和一次上2阶上一次);如果楼梯是3阶,他有3种上法(1+2,1+1+1,2+1).。。。
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
private static long GetA(int m, int n)
{
long a = 1L;
int b = m - n;
while (m > b)
{
a *= m--;
}
return a;
}
private static long GetC(int m, int n)
{
return GetA(m, n) / GetA(n, n);
}
public static long GetSum(int num)
{
long sum = 0L;
for (int i = num / 2; i >= 0; --i)
{
sum += GetC(num - i, i);
}
return sum;
}
static void Main(string[] args)
{
Console.WriteLine(GetC(6, 4));
Console.WriteLine(GetSum(10));
}
}
}