本帖最后由 pusofalse 于 2010-8-8 00:34 编辑
费了不少脑细胞啊。测试10阶用时5ms左右,递归的效率永远是个大问题~Local $iMaxLevels = 10, $iNumSeqs = 1, $sInitSeq, $iTimer = TimerInit()
For $i = 1 To $iMaxLevels
$sInitSeq &= 1
Next
$sResult = $sInitSeq & @CRLF
_StepsRecur($sInitSeq, $iMaxLevels, $sResult)
$sResult &= @CRLF & $iNumSeqs & " method(s). Time delay: " & TimerDiff($iTimer)
FileDelete("Steps.x")
FileWrite("Steps.x", $sResult)
ShellExecute("Steps.x")
Func _StepsRecur($sSeq, $i, ByRef $sResult)
If ($i < 2) Then Return
$iNumSeqs += 1
_StepsRecur($sSeq, $i - 1, $sResult)
$sSeq = StringLeft($sSeq, $i - 2) & 2 & StringTrimLeft($sSeq, $i)
$sResult &= $sSeq & @CRLF
_StepsRecur($sSeq, $i - 2, $sResult)
EndFunc ;==>_StepsRecur
|