로그인

검색

Algorithm
2012.08.13 10:07

동적 프로그래밍

조회 수 17615 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 게시글 수정 내역 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 게시글 수정 내역 댓글로 가기 인쇄

1. 팩토리얼 계산하는 문제


분할 정복

int factorial(int n)
{
if(n==1) return 1; 
else return n*factorial(n-1);

동적 프로그래밍

int factorial(int n)
{
int i;
int product = 1;
for(i=1;i<=n;i++) product *= i;
return product;
}


2. 피보나치 수열 구하는 문제


f(n) = f(n-1) + f(n-2) 인 규칙을 가지는 피보나치 수열 계산


분할 정복

int fibonacci(int n)
{
if(n==1 || n==2) return 1;
else return fibonacci(n-1) + fibonacci(n-2);
}


동적 프로그래밍

int fibonacci(int n)
{
int i,series;
int last1 = 1;
int last2 = 1;

if(n==1 || n==2) return 1;
else
{
for(i=2; i<n; i++)
{
series = last1 + last2;
last1 = last2;
last2 = series;
}

return sereis;
}
}


3. 이항 계수 구하는 문제


nCr = n-1Cr-1 + n-1Cr 공식 이용하여 이항 계수 계산


분할 정복

int bincoeff(int n, int k)
{
if(k==0 || k==n) return 1;
else return bincoeff(n-1, k-1) + bincoeff(n-1, k);
}

동적 프로그래밍

int bincoeff(int n, int k)
{
int i,j;
int B[0...n][0...n];
for(i=0; i<n; i++)
for(j=0; j<min(i,k); j++)
if(j==0 || j==i) B[i][j] = 1;
else B[i][j] = B[i-1][j-1] + B[i-1][j];
}


동적 프로그래밍으로 하는 경우 중복하여 계산하게 되는 경우를 막을 수 있으므로 계산시간이 더 빠르다.


?

  1. Programming 게시판 관련

    Date2014.11.01 CategoryTool/etc ByMoA Views115199
    read more
  2. 리스트뷰에 체크박스 추가 예제

    Date2013.05.24 CategoryJAVA/Android ByMoA Views11352
    Read More
  3. PackageBroadcastReceiver 구현

    Date2013.05.22 CategoryJAVA/Android ByMoA Views20645
    Read More
  4. 안드로이드 초간단 리스트뷰 사용법

    Date2013.04.10 CategoryJAVA/Android ByMoA Views14724
    Read More
  5. 안드로이드 프로세스 확인

    Date2013.04.09 CategoryJAVA/Android ByMoA Views10258
    Read More
  6. 안드로이드 개발 참고 사이트

    Date2013.03.31 CategoryJAVA/Android ByMoA Views9057
    Read More
  7. 안드로이드 어플 개발 사이트

    Date2013.03.11 CategoryJAVA/Android ByMoA Views10830
    Read More
  8. 이클립스에서 ADT 설치시 에러 해결

    Date2013.03.09 CategoryJAVA/Android ByMoA Views11067
    Read More
  9. Visual Studio Debug Tips

    Date2013.02.19 CategoryTool/etc ByMoA Views21982
    Read More
  10. Great summary cheat sheet (OpenCV)

    Date2013.01.04 CategorySite ByMoA Views21706
    Read More
  11. C++에서 base64로 인코딩

    Date2012.11.15 CategoryC/C++ ByNaya Views14383
    Read More
  12. Base64 decoder (binary file로 저장)

    Date2012.11.15 CategorySite ByNaya Views21456
    Read More
  13. 특정 자료형의 데이터를 binary(hex값, 2진수값)으로 변환

    Date2012.11.15 CategorySite ByNaya Views14606
    Read More
  14. Dumpbin.exe 사용

    Date2012.10.21 CategoryReversing ByNaya Views9472
    Read More
  15. [OpenCV] 얼굴 인식 예제

    Date2012.10.14 CategoryLibrary ByMoA Views12668
    Read More
  16. 코드 실행 시간 계산

    Date2012.09.27 CategoryC/C++ ByNaya Views11787
    Read More
  17. 윈도우 8 앱 개발 동영상 강의

    Date2012.09.10 CategorySite ByNaya Views12840
    Read More
  18. IT 세미나 유튜브 동영상

    Date2012.09.10 CategorySite ByNaya Views12090
    Read More
  19. 세마포어를 이용한 생산/소비자

    Date2012.08.31 CategoryAPI/MFC ByNaya Views16059
    Read More
  20. stdafx.h 사용 (미리 컴파일된 헤더)

    Date2012.08.13 CategoryAPI/MFC ByNaya Views14374
    Read More
  21. 동적 프로그래밍

    Date2012.08.13 CategoryAlgorithm ByNaya Views17615
    Read More
Board Pagination Prev 1 ... 9 10 11 12 13 14 15 16 17 18 Next
/ 18