http://nikhilkh.blogspot.kr/2012/04/dynamic-programming-beast-is-coming-run.html



package Algoexam;


public class FiboDynamic {


public  int fibo(int n){

int [] table = new int [n+1];// n 이면 아웃오브 인덱스 뜬다 

 

for(int i=0; i<table.length;i++){

if(i==0){

table[i]=1;

}else if(i==1){

table[i]=1;

}else{

table[i]=table[i-2]+table[i-1];

}

}

return table[n];

}

public int fibo1(int n){

 

if(n<=1){

return 1;

}

else{

return  fibo1(n-1)+fibo1(n-2);

}

 

}

 

public static void main(String[] args) {

FiboDynamic f = new FiboDynamic();

 

int result1=0;

int result2=0;

result1=f.fibo(5);

//result2=f.fibo1(5);

System.out.println(result1);

//System.out.println(result2);

 

}

}



'Algorithm' 카테고리의 다른 글

소인수 분해 구하기  (0) 2015.05.24
너비우선탐색 과 깊이우선탐색  (0) 2015.05.20
동적 프로그램과 분할정복의 차이  (0) 2015.05.12
문자열 뒤집기 문제  (0) 2015.05.09
이진 탐색 순회 소스  (0) 2015.05.03
Posted by 이상욱1
,