已知有一个数列:f(0) = 1,f(1) = 4,f(n+2)=2*f(n+1) + f(n),其中n是大于0的整数,求f(10)的值。
package day2;
public class Circle {
public static int jiecheng(int num){
if (num ==0){
return 1;
}else if(num == 1){
return 4;
}else{
return 2*jiecheng(num-1)+jiecheng(num-2);
}
}
public static void main(String[] args) {
System.out.println(jiecheng(3));
}
}
// f(n+2)=2*f(n+1) + f(n)
// f(2)=2*4+1=9
// f(3)=2*9+4 == 22
// f4 = 42+9=53