public class Fibonacci {
	
	private static Map<Long,Long> map = new HashMap<Long,Long>(); 
	static{
		map.put(0L, 1L);
		map.put(1L, 1L);
	}
	
	public static void main(String[] args) {
		
		long t = System.currentTimeMillis();
		Fibonacci fi = new Fibonacci();
		System.out.println(fi.cal(36L,map));
		System.out.println(System.currentTimeMillis() - t);
		System.out.println();
		t = System.currentTimeMillis();
		fi = new Fibonacci();
		System.out.println(fi.cal(36L));
		System.out.println(System.currentTimeMillis() - t);
	}
	
	public Long cal(Long n, Map<Long,Long> map){
		
		if(map.get(n) != null){
			return map.get(n);
		}else{
			long i = cal(n-1,map) + cal(n-2,map);
			map.put(n, i);
			return i;
		}
	}

 

posted on 2014-05-30 11:05  真心的不懂  阅读(322)  评论(0编辑  收藏  举报