找出特定組合

<!--本過程完成對數組元素取特定組合-->

<%
dim result,geted
dim limvalue
ysstr
=split("1,20,30,4,51",",")
main
''------------------main完成初始化,及結果處理--------------
sub main
'----------------------初始化-----------
    limvalue=75
    strsub
=0
    
for j=1 to ubound(ysstr)
        strsub
=strsub&","&j
    
next
    strsub
=split(strsub,",")
'-----------------------開始組合---------------
    call combo(strsub)
'------------------------result是全局變量,存放下標--------------
    xb=split(result,",")
'------------------------輸出結果-----------------------
    for i=0 to ubound(xb)
        xbs
=cint(xb(i))
        ww ysstr(xbs)
    
next
end sub
''-----------------------main結束-------------------------

''---------------------主過程 combo-----------------------
sub combo(str)
for i=0 to ubound(str)
if geted then
    
exit sub
end if
    ftmp
=pick(str,i)
    combo(ftmp)
next
end sub
''----------------------子過程pick---------------------------
function pick(strarray,k)
    
for i=0 to ubound(strarray)
        
if i<>then
        temp
=temp&strarray(i)&","
        xb=cint(strarray(i))
        numtmp
=numtmp+cint(ysstr(xb))
        
end if
    
next
            
if numtmp=limvalue then  '如果結果等於限制的結果
            ww numtmp
            geted
=true
            result
=left(temp,len(temp)-1)
            
end if
    
if len(temp)>1 then
    temp
=left(temp,len(temp)-1)
    
end if
    
    pick
=split(temp,",")
end function

sub ww(t)
    response.write t
    response.write 
"<BR>"
    response.flush
end sub
%
>

简单测试下执行速度:8秒/10万次

Posted on 2005-04-07 15:03  古代  阅读(427)  评论(0编辑  收藏  举报