'=========================================================================== ' Subject: BEST FIT (KNAPSACK) ALGORITHM Date: 05-28-00 (03:41) ' Author: Wayne Henderson Code: QB, QBasic, PDS ' Origin: whenders@becon.org Packet: ALGOR.ABC '=========================================================================== ' Best fit (Knapsack) algorithm DEFINT A-Z:DIM SHARED K,S,B&,Z&:V1 'Created by PostIt! 7.2 SUB V1:OPEN "O",1,"KNAPSACK.ZIP",4^6:Z&=4023:?STRING$(50,177); U"%up()%9%%%#-%%wf3M[>)#d)(.%%l,%%%,%%%%qx%ySgfax.zh,>Sa5iw]cx$Z3 U"G6CicSsQK3u,CJ%qX\iK-K)DlKz.&q.xLm_bDqtNvu#H3F1JyY8Wj4_KHrVBHVA U"hcCGmf)6GAFCXPveGmoG9*WVWjta_g2YsPpJWn;1i1kd(%w]]?^Rn U"OfP(3'#ns=8Q[A_6S5]T$b:8Ir2Sd[5_uDd*mK1RFCl'__\OL$B$pe6$AQC$^E= U"SZA9][**GxJV_iRoVZ(7&-E+q](r.j3[OIT%rQnYSinma U"tE29CY)tiodsA5_k?;8eg/.GgcFeOcHKnw#S7GH%7 U"(H1Fau5Z;+BCEVEN9V)gFeI;egS/8Hf2f-k3D;7r1;-J?]7D.RLFfI(ifd,>JPlEwxPbuf=J(aqP*u*FZeQB&'ziWeVZ7upI1h>XrPoa U"s0^Bb/:-JUW3m\NMS?;tzUVcHdp4iQe\P%'X7Rbqez6,s_CCFV95p.PT<Y_#)%%'%0%%,%%%%k%nySgIfx\%;<>Smj5w]=& U"N=^vDP:g1]kwB6jk[Y2D'D%0r$ydb7yRo5Y%*6eeFNp8^qp)..imSy)OZ*4^^u/O&;(o%3DBec2pe7[e)k5:A2w6xiJY$Jaw U"3o_2gR'e-=^XOc+RJjV52a[EU#%RTlTFU5NhGC;'pA[3il666H4$-5\2gp_4$'a U"M0L#v:hFOBdsc))4B&cJ>w0I/SoZ-N[GxaZ9X6S.8Z5_#liuotut9hI\U>0j^2K U"%tus_VfTfZe]'OGl)/xjCQs1egn8DW((jEx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