描述 |
|
---|---|
知识点 | 查找,搜索,排序 |
运行时间限制 | 10M |
内存限制 | 128 |
输入 | 输入int型表示month |
输出 | 输出兔子总数int型 |
样例输入 | 9 |
样例输出 | 34 |
递归 || 斐波拉契数列
递归实现:
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
while(sc.hasNext()){
int month=sc.nextInt();
System.out.println(count(month));
}sc.close();
}
private static int count(int n){
int sum=0;
if(n==1||n==2){return 1;}
return count(n-1)+count(n-2);
}
}
斐波那契数列
(如上,又称为“比内公式”,是用
无理数表示有理数的一个范例。)
注:此时