로그인

검색

Algorithm
2012.08.13 10:07

동적 프로그래밍

조회 수 3241 추천 수 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 Views15455
    read more
  2. What does set -e mean in a bash script?

    Date2021.04.29 CategoryTool/etc ByOBG Views3368
    Read More
  3. What does the last “-” (hyphen) mean in options of `bash`?

    Date2021.04.29 CategoryTool/etc ByOBG Views2797
    Read More
  4. What to use instead of “addPreferencesFromResource” in a PreferenceActivity?

    Date2013.06.13 CategoryJAVA/Android ByMoA Views2979
    Read More
  5. What's the difference between comma separated joins and join on syntax in MySQL?

    Date2022.06.09 CategoryDatabase ByOBG Views2777
    Read More
  6. Which Font is the default for MFC Dialog Controls

    Date2013.06.12 CategoryAPI/MFC ByMoA Views3345
    Read More
  7. Win32 Socket Class

    Date2012.08.02 CategoryLibrary ByNaya Views3595
    Read More
  8. Windows 10 앱 개발(UWP)

    Date2015.10.13 CategoryAPI/MFC ByMoA Views3383
    Read More
  9. WTL 정리

    Date2013.12.22 CategoryAPI/MFC ByMoA Views3582
    Read More
  10. XML 파싱하기

    Date2013.08.06 CategoryJAVA/Android ByMoA Views8945
    Read More
  11. 강화학습 학습 관련 정리

    Date2022.08.10 CategoryDeeplearning ByOBG Views2854
    Read More
  12. 개발에 도움되는 사이트 (초보 개발자 꿀팁)

    Date2023.01.28 CategorySite ByOBG Views2491
    Read More
  13. 개발자를 위한 각 기업 오픈소스 공유 사이트 (주로 모바일)

    Date2012.08.02 CategorySite ByNaya Views3690
    Read More
  14. 검색엔진 개발자 그룹

    Date2013.08.30 CategorySite ByMoA Views2758
    Read More
  15. 고수가 절대 알려주지 않는 C/C++ 팁

    Date2011.09.23 CategoryC/C++ By너울 Views2972
    Read More
  16. 고양이 밖으로 못나가게 하기

    Date2013.11.10 CategoryPython ByMoA Views3421
    Read More
  17. 고양이 움직이기

    Date2013.11.08 CategoryPython ByMoA Views3445
    Read More
  18. 구글 검색 알고리즘의 원리

    Date2012.08.02 CategoryAlgorithm ByNaya Views3313
    Read More
  19. 나이 들어가는 프로그래머 - [발표영상] 요약

    Date2025.02.14 CategoryTool/etc ByOBG Views2009
    Read More
  20. 내 마음대로 선정한 머신러닝/딥러닝 학습 추천 서적

    Date2023.08.14 CategoryDeeplearning ByOBG Views2909
    Read More
  21. 다국어를 위한 StringTable, LoadString

    Date2013.12.22 CategoryAPI/MFC ByMoA Views4887
    Read More
Board Pagination Prev 1 ... 6 7 8 9 10 11 12 13 14 15 Next
/ 15