日期:2014-05-20  浏览次数:20682 次

有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问某个月的兔子总数为多少?
有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问某个月的兔子总数为多少?(网上的答案是错的,大家分析一下)  我的分析如下:*
 * 第一个月 2
 * 第二个月 2
 * 第三个月 2+2/2*2=4   
 *
 * 第四个月 4+2=6
 * 第五个月 6+2=8
 * 第六个月 8+2*2=12
 * 第七个月 12+2*2=16
 * 第八个月 16+2*2=18
 * 第九个月 18+2*2*2=26
 * 第十个月 26+2*2*2=34
 * 
 */
请用java写出实现代码
------最佳解决方案--------------------
lz
注意翻本站内相同帖子啊

//农场养牛问题
public class Cow {
public static int count = 0;
public Cow(int year) {
count++;
for (int i = 3 + year; i <= 10; i++) {
new Cow(i);
}
}

public static void main(String[] args) {
new Cow(0);
System.out.println(count);
}
}


10表示10个月,改成n就行
------其他解决方案--------------------
你算错了
第七个月 12+2*2=16

这个错了,因为第四个月还出生了一对,所以应该是12 + 3 * 2 = 18;


int born = 2;
int first = 0;
int second = 0;
int third = 0;

for (int i = 1; i <= 10; i++) {
third += second;
second = first;
first = born;
born = third;
System.out.println("第" + i + "个月:" + (born + first + second + third));
}


------其他解决方案--------------------
参考①

参考②

参考③




------其他解决方案--------------------
http://topic.csdn.net/t/20030226/14/1468297.html#
------其他解决方案--------------------
弟递归 很容易实现啊,楼主 你先分析一下 总结出 通项公式

然后可以用数学归纳法证明你的 归纳,然后用 编程语言 表达出 你的算法 ,just this
------其他解决方案--------------------
曾经有人也在这里讨论过这个问题,只不过是“牛”而不是“兔”。自己找找看吧
------其他解决方案--------------------
一只,因为这是只兔爷
------其他解决方案--------------------
农夫养牛问题的第三个变种。
------其他解决方案--------------------

public class RabitGame {
public static final int N = 10;
public static void main(String[] args) {
int[] rabits = new int[N+1];
rabits[0] = rabits[1] = rabits[2] = 2;
for(int i=3; i<=N; i++) {
rabits[i] = rabits[i-1] + rabits[i-3];
}

for(int i=0; i<rabits.length; i++) {
System.out.println(i + "个月后兔子的数量为:" + rabits[i]);
}
}
}
/*
0个月后兔子的数量为:2
1个月后兔子的数量为:2
2个月后兔子的数量为:2
3个月后兔子的数量为:4
4个月后兔子的数量为:6
5个月后兔子的数量为:8
6个月后兔子的数量为:12
7个月后兔子的数量为:18
8个月后兔子的数量为:26
9个月后兔子的数量为:38
10个月后兔子的数量为:56
楼上好快呀,O(∩_∩)O哈哈~
*/

------其他解决方案--------------------