Fork me on GitHub

NYOJ之Fibonacci数

-------------------------------------------------------------

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

posted @ 2016-08-21 00:45  CC11001100  阅读(133)  评论(0编辑  收藏  举报