Subset sum problem: Difference between revisions
Content added Content deleted
(→version 2: approximated the version 2 's speed vs. version 1. -- ~~~~) |
m (→version 2: optimized y-1 expression into ym. -- ~~~~) |
||
Line 851: | Line 851: | ||
do j=1; L=!.d; do d=2 for ym; L=L !.d; end /*d*/ |
do j=1; L=!.d; do d=2 for ym; L=L !.d; end /*d*/ |
||
_=!.1; s=#._ |
_=!.1; s=#._ |
||
do k=2 for |
do k=2 for ym until s>target; _=!.k; s=s+#._; end /*sum weights.*/ |
||
if s==target then call telly |
if s==target then call telly |
||
!.y=!.y+1; if !.y==base then if .combUp(ym) then leave |
!.y=!.y+1; if !.y==base then if .combUp(ym) then leave |