-------------------------------------------------------------
AC代码:
1 import java.util.Scanner; 2 3 public class Main { 4 5 public static void main(String[] args) { 6 7 Scanner sc=new Scanner(System.in); 8 9 int times=sc.nextInt(); 10 11 while(times-->0){ 12 int n=sc.nextInt(); 13 long ans=fibonacci(n); 14 System.out.println(ans); 15 } 16 17 } 18 19 public static long book[]=new long[21]; 20 21 public static long fibonacci(int n){ 22 if(n==1 || n==2) return 1; 23 return book[n]=fibonacci(n-1)+fibonacci(n-2); 24 } 25 26 }
题目来源: http://acm.nyist.net/JudgeOnline/problem.php?pid=13
时间: 2024-10-12 12:34:34