¡¶¼ÆËã»úËã·¨»ù´¡¡·µÚÈý°æ - ¿ÎºóÏ°Ìâ´ð°¸

end HEAPSORT 5.11£®¢Ù Ö¤Ã÷Èç¹ûÒ»¿ÃÊ÷µÄËùÓÐÄÚ²¿½ÚµãµÄ¶È¶¼Îªk£¬ÔòÍⲿ½ÚµãÊýnÂú×ãn mod (k-1)=1.

¢Ú Ö¤Ã÷¶ÔÓÚÂú×ã n mod (k-1)=1µÄÕýÕûÊýn£¬´æÔÚÒ»¿Ã¾ßÓÐn¸öÍⲿ½ÚµãµÄkÔªÊ÷T(ÔÚÒ»¿ÃkÔªÊ÷ÖУ¬Ã¿¸ö½ÚµãµÄ¶ÈÖÁ¶àΪk)¡£½ø¶øÖ¤Ã÷TÖÐËùÓÐÄÚ²¿½ÚµãµÄ¶ÈΪk.

Ö¤Ã÷£º¢Ù Éèij¿ÃÊ÷ÄÚ²¿½ÚµãµÄ¸öÊýÊÇm£¬Íⲿ½áµãµÄ¸öÊýÊÇn£¬±ßµÄÌõÊýÊÇe£¬

ÔòÓÐ

e=m+n-1ºÍ e=mk

mk=m+n-1 ? (k-1)m=n-1 ? n mod (k-1)=1

¢Ú ÀûÓÃÊýѧ¹éÄÉ·¨¡£

µ±n=1ʱ£¬´æÔÚÍⲿ½áµãÊýĿΪ1µÄkÔªÊ÷T£¬²¢ÇÒTÖÐÄÚ²¿½áµãµÄ¶ÈΪ

k£»

¼ÙÉèµ± n¡Üm£¬ÇÒÂú×ãn mod (k-1)=1ʱ£¬´æÔÚÒ»¿Ã¾ßÓÐn¸öÍⲿ½áµãµÄ

kÔªÊ÷T£¬ÇÒËùÓÐÄÚ²¿½áµãµÄ¶ÈΪk£»

ÎÒÃǽ«Íⲿ½áµãÊýΪn(nΪÂú×ãn¡Üm£¬ÇÒn mod (k-1)=1µÄ×î´óÖµ)µÄ·û

ºÏÉÏÊöÐÔÖʵÄÊ÷TÖÐij¸öÍⲿ½áµãÓÃÄÚ²¿½áµãaÌæ´ú£¬ÇÒ½áµãaÉú³ök¸öÍⲿ½áµã£¬Ò×ÖªÐÂÉú³ÉµÄÊ÷T¡¯ÖÐÍⲿ½áµãµÄÊýĿΪn+(k-1)£¬ÏÔÈ»nΪÂú×ãn mod (k-1)=1£¬ÇÒ±Èm´óµÄ×îСÕûÊý£¬¶øÊ÷T¡¯Ã¿¸öÄÚ½áµãµÄ¶ÈΪk£¬¼´´æÔÚ·ûºÏÐÔÖʵÄÊ÷¡£

×ÛºÏÉÏÊö½á¹û¿ÉÖª,ÃüÌâ³ÉÁ¢¡£

5.12£®¢Ù Ö¤Ã÷Èç¹ûn mod (k-1)=1£¬ÔòÔÚ¶¨Àí5.4ºóÃæËùÃèÊöµÄÌ°ÐĹæÔò¶ÔÓÚËùÓеģ¨q1,q2,?, qn£©Éú³ÉÒ»¿Ã×îÓŵÄkÔª¹é²¢Ê÷¡£

¢Ú µ±£¨q1,q2,?, q11£©=£¨3,7,8,9,15,16,18,20,23,25,28£©Ê±£¬»­³öʹÓÃÕâÒ»¹æÔòËùµÃµ½µÄ×îÓÅ3Ôª¹é²¢Ê÷¡£ ½â£º¢Ùͨ¹ýÊýѧ¹éÄÉ·¨Ö¤Ã÷£º

¶ÔÓÚn=1£¬·µ»ØÒ»¿ÃûÓÐÄÚ²¿½áµãµÄÊ÷ÇÒÕâ¿ÃÊ÷ÏÔÈ»ÊÇ×îÓŵġ£

¼Ù¶¨¸ÃËã·¨¶ÔÓÚ£¨q1,q2,?, qm£©£¬ÆäÖÐm =(k-1)s+1 (0 ¡Ü s)£¬¶¼Éú

³ÉÒ»¿Ã×îÓÅÊ÷.

ÔòÖ»ÐèÖ¤Ã÷¶ÔÓÚ(q1,q2,?, qn)£¬ÆäÖÐn=(k-1)(s+1)+1£¬Ò²ÄÜÉú³É×îÓÅ

Ê÷¼´¿É¡£

²»Ê§Ò»°ãÐÔ£¬¼Ù¶¨q1¡Üq2¡Ü?¡Üqn£¬ÇÒq1,q2,?, qkÊÇËã·¨ËùÕÒµ½µÄk

¿ÃÊ÷µÄWEIGHTÐÅÏ¢¶ÎµÄÖµ¡£ÓÚÊÇq1,q2,?, qk¿ÃÉú³É×ÓÊ÷T£¬ÉèT?ÊÇÒ»¿Ã¶ÔÓÚ£¨q1,q2,?, qn£©µÄ×îÓÅkÔª¹é²¢Ê÷¡£ÉèPÊǾàÀë¸ù×îÔ¶µÄÒ»¸öÄÚ²¿½áµã¡£Èç¹ûPµÄk¸ö¶ù×Ó²»ÊÇq1,q2,?, qk£¬Ôò¿ÉÒÔÓÃq1,q2,?, qkºÍPÏÖÔڵĶù×Ó½øÐн»»»£¬ÕâÑù²»Ôö¼ÓT?µÄ´øȨÍⲿ·¾¶³¤¶È¡£Òò´ËTÒ²ÊÇÒ»¿Ã×îÓŹ鲢Ê÷ÖеÄ×Ó

Ê÷¡£ÓÚÊÇÔÚT?ÖÐÈç¹ûÓÃÆäȨΪq1+q2+?+qkµÄÒ»¸öÍⲿ½áµãÀ´´ú»»T£¬ÔòËùÉú³ÉµÄÊ÷T??ÊǹØÓÚ(q1+q2+?+qk,qk?1,?,qn)µÄÒ»¿Ã×îÓŹ鲢Ê÷¡£ÓɹéÄɼÙÉ裬ÔÚʹÓÃÆäȨΪq1+q2+?+qkµÄÄǸöÍⲿ½áµã´ú»»ÁËTÒԺ󣬹ý³ÌTREEת»¯³ÉÈ¥ÇóÈ¡Ò»¿Ã¹ØÓÚ(q1+q2+?+qk,qk?1,?,qn)µÄ×îÓŹ鲢Ê÷¡£Òò´ËTREEÉú³ÉÒ»¿Ã¹ØÓÚ(q1,q2,?, qn)µÄ×îÓŹ鲢Ê÷¡£

6.2£®Ð޸Ĺý³ÌALL_PATHS£¬Ê¹ÆäÊä³öÿ¶Ô½áµã£¨i,j£©¼äµÄ×î¶Ì·¾¶£¬Õâ¸öÐÂËã·¨µÄʱ¼äºÍ¿Õ¼ä¸´ÔÓ¶ÈÊǶàÉÙ£¿

Procedure ShortestPath(COST, n, A, Max)

integer i , j, k

real COST(n, n), A(n, n), Path(n, n), Max

for i¡û1 to n do

for j¡û1 to n do

A(i ,j)¡ûCOST(i ,j)

if i¡Ùj and A(i, j)¡ÙMax then Path(i, j )¡ûj else Path(i, j)¡û0 endif

repeat

repeat

for k¡û1 to n do

for i¡û1 to n do

for j¡û1 to n do

if A(i,j)>A(i,k)+A(k,j)

then A(i,j)¡ûA(i,k)+A(k,j) Path(i,j)¡ûPath(i,k) endif

repeat repeat

repeat

for i¡û1 to n do

for j¡û1 to n do

print(¡°the path of i to j is ¡± i ) k¡ûpath(i, j) while k¡Ù0 do print( ,k) k¡ûpath(k, j) repeat repeat repeat

end ShortestPath

ʱ¼ä¸´ÔÓ¶ÈO(n3)£¬¿Õ¼ä¸´ÔÓ¶ÈO(n2)

6.4£®¢ÙÖ¤Ã÷Ëã·¨OBSTµÄ¼ÆËãʱ¼äÊÇO(n2)¡£

¢ÚÔÚÒÑÖª¸ùR(i, j)£¬0¡Üi < j¡Ü4µÄÇé¿öÏÂдһ¸ö¹¹Ôì×îÓŶþ·Ö¼ìË÷Ê÷TµÄËã·¨¡£Ö¤Ã÷ÕâÑùµÄÊ÷ÄÜÔÚO(n)ʱ¼äÄÚ¹¹Ôì³öÀ´¡£

½â£º¢Ù ½«CÖÐÔªËصļӷ¨¿´×ö»ù±¾ÔËË㣬ÔòËã·¨OBSTµÄʱ¼ä¸´ÔÓÐÔΪ£º

nn?mnn?m??(R(i?1,j)?R(i,j?1)?1)???(R(i?1,i?m)?R(i,i?m?1)?1)?m?2i?0m?2i?0n?m?2(R(n?m?1,n)?R(0,m?1)?n?m?1)?O(n2)

¢Ú Procedure BuildTree(m, n, R, Root)

integer R(n,n), k

TreeNode Root, LR, RR k¡ûR(m,n)

if k¡Ù0 then data(Root)¡ûk,

BuileTree(m, k-1, R, LR), BuileTree(k, n, R, RR)

left(Root)¡ûLR, right(Root)¡ûRR

else data(Root)¡ûm, left(Root)¡ûnull, right(Root)¡ûnull, endif

end BuildTree

ʱ¼ä¸´ÔÓÐÔ·ÖÎö£ºT(n)=c+T(k)+T(n-k-1)£¬´ËµÝÍÆʽ±£Ö¤Ëã·¨µÄʱ¼ä¸´ÔÓÐÔΪO(n)£¬Ò²¿É´ÓµÝ¹éµÄ½Ç¶È³ö·¢£¬µÝ¹éµÄ´ÎÊýÕýÊǽáµãµÄ¸öÊý£¬¶øÿ´ÎµÝ¹éʱ¼ä¸´ÔÓÐÔΪ³£Êý£¬ËùÒÔËã·¨µÄʱ¼ä¸´ÔÓ¶ÈҲΪO(n)¡£

6.8£®¸ø³öÒ»¸öʹµÃDKNAP(Ëã·¨6.7)³öÏÖ×Çé¿öµÄÀý×Ó£¬ËüʹµÃ|Si|=2i, 0¡Üi

½â£ºÈ¡(P1,P2,?,Pi,?)=(W1,W2,?,Wi,?)=(20,21,?,2i-1,?)

PºÍWÈ¡ÖµÏàͬ£¬Ê¹Ö§ÅäÔ­Ôò³ÉÁ¢£¬Ò²¾ÍÊÇ˵²»»áÒòΪ֧ÅäÔ­Ôò¶øɾ³ýÔªËØ£»Ö»ÒªËµÃ÷²»»á³öÏÖÏàͬԪËر»É¾³ýÒ»¸öµÄÇéÐΣ¬¼´¿ÉÖªÊÇ×µÄÇé¿ö¡£¿ÉÓùéÄÉ·¨Ö¤Ã÷´Ë½áÂÛ¡£

ÁªÏµ¿Í·þ£º779662525#qq.com(#Ì滻Ϊ@)