首页 > 其他 > 详细

兔子产兔

时间:2014-12-14 21:21:32      阅读:256      评论:0      收藏:0      [点我收藏+]
#include <stdlib.h>
#include "oj.h"
#include <iostream>
using namespace std;
// 功能:获取第nValue1个月出生多少对兔子
// 输入: nValue1为正整数
// 输出:无
// 返回:第nValue1个月出生多少对兔子

//根据前几个月的结果可以推断出该函数满足f(n) = f(n-1) + f(n-2)
unsigned int GetBirthRabbitNum(unsigned int  nValue1)
{
	if (nValue1 == 1 || nValue1 == 2)
	{
		return 1;
	}
	else
	{
		return GetBirthRabbitNum(nValue1 -1 )+GetBirthRabbitNum(nValue1 -2);
	}
}

int main()
{
	int num;
	while (cin>>num)
	{
		cout<<GetBirthRabbitNum(num)<<endl;
	}
	return 0;
}

兔子产兔

原文:http://blog.csdn.net/xiaohanstu/article/details/41927777

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!