# 동적 계획 (Dynamic Programming)

• View
195

0

Embed Size (px)

DESCRIPTION

동적 계획 (Dynamic Programming). 동적 계획법. 분할정복식 알고리즘 설계법 나누어진 문제가 연관이 없을 경우 Cf) 피보나찌 알고리즘 동적계획법 (Dynamic programming) 상향식 해결법 (bottom-up approach) 분할정복식 방법과 마찬가지로 문제를 나눈 후 , 나누어진 부분들을 먼저 푼다 . 그러나 이미 풀어서 답을 알고 있는 부분의 결과가 다시 필요한 경우에는 반복하여 계산하는 대신에 이미 계산된 결과를 그냥 사용한다. 동적 계획법. 전략 - PowerPoint PPT Presentation

### Text of 동적 계획 (Dynamic Programming)

• (Dynamic Programming)

• Cf) (Dynamic programming) (bottom-up approach) , . .

• => . . .

• () int fib (int n) { if (n 0) { f[1] = 1; for (i = 2; i
• : int bin(int n,k){if k=0 or k=n then bin=1;else bin(n,k)= bin(n-1,k-1)+bin(n-1,k);}

• . .? , :

: n=1; : n < N :

:

• : (recursive property)

• int bin2(int n,k){ index i,j; int B[0..n,0..k];for (i=0; in; i++)for (j=0; j min(i,k); j++)if (j=0 or j=i) B[i,j]=1;else B[i,j] = B[i-1,j-1] + B[i-1,j];return B[n,k];}

• : B[i,j] = B[i-1,j-1] + B[i-1,j]; : n, k j-

• : ?

• (vertex, node)(edge, arc)(weight)(path) (Simple path)(cycle)(cyclic) (acyclic) (length) (adjacent vertex)

• (Shortest Path) : : ,

(optimization problem) , (optimal solution)

• : (brute-force algorithm) , . n , . i j , , .i n-2, , n-3 , , (n-2)(n-3)1 = (n-2)! . , !

• - (adjacent matrix) : W

• Floyd ??

void floyd(int n, const number W[][], number D[][]) { int i, j, k; D = W; for(k=1; k

• Floyd void floyd2(int n, const number W[][],number D[][], index P[][]) { index i, j, k; for(i=1; i
• Path(5,3)void path(index q,r) { if (P[q][r] != 0) { path(q,P[q][r]); cout
• (optimal) (recursive property)

• , (the principle of optimality) .)

• (Longest Path)

• (Matrix-chain Multiplication)(ixj) x (jxk) : ?ixjxk

29=1x7+2x2+3x6 ixk

• : : .: ?tn: n (A1, A2, , An) tn A1 : tn-1tn An : tn-1

• : ?

• :

• )

• P[i][j]

• ?k-: (j-1)-i+1=i+diagonal-1-i+1=diagonali-: n-diagonal

• P[i][j] void order(index i, index j) { if (i == j) cout
• ?Yao(1982)

Hu and Shing(1982,1984)

• (tree)(root) (child node) (recursive structure)

(binary tree)(depth)= level

• (balanced binary tree)

• (binary search tree) . , .

• ? ?

• (search time) : depth(key)+1pi: keyi ci: ?

• ? ? ? .keyi keyj

!

• : keyk ,

• :

• )

• k-: min j-1+1=i+diagonal-i+1=diagonal+1 i-: n-diagonal

• (Traveling Salesperson Problem) (Euler cycle): (Hamiltonian cycle): ( ; optimal tour) Length[1,2,3,4,1]=22Length[1,3,2,4,1]=26Length[1,3,4,2,1]=21

• (n-1)! ? .

W[i,j]: V: A: A VD[vi,A]: A vi v1

• A={v3} D[v2,A] = length[v2,v3,v1] = A={v3,v4} D[v2,A] = min(length[2,3,4,1],length[2,4,3,1]) = min(20,) = 20

Length of an optimal tour = min(W[1,j] + D[vj,V-{v1,vj}]) 2jn

D[vi,A] = min(W[i,j] + D[vj,A-{vj}]) if A vjAD[vi,] = W[i,1]

• void travel(int n, const number W[], number& minlength){ index i,j,k; number D[1..n, subset of V-{v1}]; for i=2 to n D[i,0] = W[i,1]; for k=1 to n-2 for all subsets A V-{vi} s.t. |A|=k for i s.t. i1 & vi A { D[i,A] = min(W[i,j] + D[j,A-{vj}]);} j:vjAD[1,V-{v1}] = min(W[1,j] + D[j,V-{v1,vj}]); 2jnminlength = D[1,V-{v1}];}

• ? .n = 20n 30 ? NP

Recommended

Documents
Documents
Documents
Marketing
Documents
Documents
Documents
Documents
Documents
Documents
Documents
Documents