فصل پنجم

Click here to load reader

Upload: yoshe

Post on 05-Jan-2016

61 views

Category:

Documents


3 download

DESCRIPTION

درس طراحی الگوریتم ها. فصل پنجم. راهبرد عقبگرد Backtracking approach. مدرس: سید محمد بیدکی. بهار 1392. هزارتوی شمشادی. اگر سعی کنید راه خود را در هزارتوی شمشادی بیابید، راهی ندارید جز دنبال کردن مسیری تا اینکه به بن بست برسید. در این حالت برمی گردید و راهی دیگر را امتحان می کنید. - PowerPoint PPT Presentation

TRANSCRIPT

Backtracking approach : 1392

- : - 2 . . .

/57 - : - 3 . .

. n . n nn . .

/57 ( ) - : - 4 ( preorder) . . .

/57 - : - 5 . . . . .

/57 (State Space) - : - 6 ( ) () . n n=4 . : 4444

/57 - : - 7 . .

/57 - : - 8

/57 - : - 9

. . ./57

n (n=4) - : - 10/57 n (n=4) - : - 11

/57 n - : - 12 . n . col(i) i . : col(i) = col(k) : |col(i)-col(k)| = |i-k|

/57 n - : - 13

/57 - : - 14 . :1 n 1 n2 2 ... nn n1+n+n2+n3++nn = (nn+1-1)/n-1 n=8 19173961 . . .1+n+n(n-1)+n(n-1)(n-2)+.+n! n=8 109601

/57 ... - : - 15 3 1: 2:

/57 - : - 16 n wi () W . n W .

/57 - : - 17 w1 w1 . . wi wi wi 0 .

/57 (n=3 W=6) - : - 18

/57 - : - 19 i wi+1 . weight i : weight + wi+1 > W . total : weight + total < W . weight = W . ./57 (n=4 W=13) - : - 20

/57 - : - 21

/57 - : - 22 W . ( : : ). . :

/57 - : - 23 weight i : weight W . : pi/wi . (bound). profit . bound totweight profit weight . bound totweight W . bound .

/57 ... - : - 24 i k W :

maxprofit . bound maxprofit i .

/57 - : - 25

/57

- : - 261) (0,0)Profit = 0$Weight = 0Maxprofit = 0$

totweight = 7Bound = 115$ : (weight maxprofit)/57 - : - 27

/57

- : - 282) (1,1)Profit = 40$Weight = 2Maxprofit = 0$ 40$

totweight = 7Bound = 115$ : (weight maxprofit)/57 - : - 29

/57

- : - 303) (2,1)Profit = 70$Weight = 7Maxprofit = 40$ 70$

totweight = 7Bound = 115$ : (weight maxprofit)/57 - : - 31

/57 - : - 324) (3,1)Profit = 120$Weight = 17 : (weight > 16)Maxprofit = 70$ (2,1)/57 - : - 33

/57 - : - 345) (3,2)Profit = 70$Weight = 7Maxprofit = 70$

totweight = 7 + 5 = 12Bound = 70+ 10 = 80$ : (weight maxprofit)/57 - : - 35

/57 - : - 366) (4,1)Profit = 80$Weight = 12Maxprofit = 70$ 80$ Bound = 80$ : (bound maxprofit) (3,2)/57 - : - 37

/57 - : - 387) (4,2)Profit = 70$Weight = 7Maxprofit = 80$ Bound = 70$ : (bound maxprofit) (1,1)/57 - : - 39

/57 - : - 408) (2,2)Profit = 40$Weight = 2Maxprofit = 80$totweight = 2 + 10 = 12Bound = 40$ + 50$ + (16-12) 2$ = 98$ : (weight maxprofit)/57 - : - 41

/57 - : - 429) (3,3)Profit = 90$Weight = 12Maxprofit = 80$ 90$totweight = 12Bound = 90$ + (16-12) 2$ = 98$ : (weight maxprofit)/57 - : - 43

/57 - : - 4410) (4,3)Profit = 100$Weight = 17Maxprofit = 90$ : (weight 16) maxprofit . (3,3)/57 - : - 45

/57 - : - 4611) (4,4)Profit = 90$Weight = 12Maxprofit = 90$ Bound = 90$ : (bound maxprofit) (2,2)

/57 - : - 47

/57 - : - 4812) (3,4)Profit = 40$Weight = 2Maxprofit = 90$totweight = 2 + 5 = 7Bound = 40$ + 10$ = 50$ : (bound maxprofit) (0,0)

/57 - : - 49

/57 - : - 5013) (1,2)Profit = 0$Weight = 0Maxprofit = 90$totweight = 0+ 5 + 10 = 15Bound = 0$ + 30$ + 50$ +(16-15) 2$ = 82$ : (bound maxprofit) (0,0) . .

/57 - : - 51

/57 - : - 52

/57 - : - 53

/57

- : - 54/57 - : - 55

/57 - : - 56 : O (minimum (2 , nW)) (2n) .

. . (1974) ./57 ( //) - : - 57 C++ C# Java . C++ C# Java .

. (GUI) ./57