按照楼主思路试试,是不是这个意思:
从m个数中取出n个数的和等于k的组合
程序代码:
CREATE CURSOR dd (cc C(254))
m = 10
k = 80
DIMENSION aa[m]
FOR i = 1 TO m
aa[i] = i*10
ENDFOR
_f(@aa, k)
GO TOP
BROWSE
RETURN
FUNCTION _f(aa, k)
LOCAL i
FOR i = 1 TO ALEN(aa)
IF aa[i] > k
EXIT
ENDIF
ENDFOR
DIMENSION aa[i-1]
FOR i = 1 TO ALEN(aa)
LOCAL bb[i]
_ff(@aa, @bb, i, 1, 1, k)
ENDFOR
ENDFUNC
FUNCTION _ff(aa, bb, n, ai, bi, k)
LOCAL i, dd, ss
IF (n == 0)
dd = bb[1]
ss = TRANSFORM(bb[1])
FOR i = 2 TO bi-1
dd = dd + bb[i]
ss = ss + "," + TRANSFORM(bb[i])
ENDFOR
IF dd == k
INSERT INTO dd VALUES (ss)
ENDIF
RETURN
ENDIF
FOR i = ai TO ALEN(aa)
bb[bi] = aa[i]
_ff(@aa, @bb, n-1, i+1, bi+1, k)
ENDFOR
ENDFUNC
[
本帖最后由 吹水佬 于 2015-4-10 09:52 编辑 ]