public class Demo {
static int[] help;
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc= new Scanner(System.in);
int N = sc.nextInt();
help = new int[N+1];
int result = f1(N);
System.out.println(result);
sc.close();
}
private static int f1(int n) {
// TODO Auto-generated method stub
//记忆型递归 要点:计算前先查询 递归后记录
if (n==0) {
return 1;
}
if (n==1) {
return 1;
}
if (n==2) {
return 2;
}
return f1(n-1)+f1(n-2)+f1(n-3);
}
}
10-24
1969
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交