class Program
{
/// <summary>
/// 每过一个村庄丢失之前的一般还多一只,7个村后还剩下2只
/// </summary>
/// <param name="cun"></param>
/// <returns></returns>
public int yangshu(int cun)
{
int sum = 0;
if (cun==7)
{
sum = 2;
return sum;
}
sum = (yangshu(cun + 1) + 1) * 2;//5天为例:sum=(yangshu(cun+1)+1)*2→sum=(yangshu(5+1)+1)*2→sum=((yangshu(6+1)+1)*2+1)*2
return sum;//yangshu(5+1)=(yangshu(6+1)+1)*2
}
static void Main(string[] args)
{
int sum = new Program().yangshu(0);
Console.WriteLine(sum);
Console.ReadLine();
}
}
时间: 2024-12-12 04:25:50