快速组合数c(n,k)=n*(n-1)*(n-2)*...*(n-k+1)/1*2*3*...*k 的求法:
【相关文章:儿时的编程算法心得笔记】【扩展阅读:下载网页中的所有资源】
【扩展信息:人工智能·我对智能软件的一些思】 function zdgys(byval x as long, byval y as long) as long ´get greatest common divisor最大公约数 dim temp as long if x > y then temp = x: x = y: y = temp ´let x < y do temp = y mod x if temp = 0 then zdgys = x: exit function y = x x = temp loop end function sub calc(byval n as long, byval k as long, optional byref cnk as string) ´计算c(n,k),赋值给cnk dim xys() as integer, x() as integer, y() as integer, result() as string, i as long, j as long, t as long, temp as long, stimer as double if n < 0 or n < k then exit sub stimer = timer if k = n or k = 1 then cnk = n: goto r ´特殊情况 if n > 0 and k = 0 then cnk = 1: goto r ´特殊情况 if k > n - k then k = n - k ´减少计算量 dim nn() as long, nk() as long redim nn(1 to k) redim nk(1 to k) for i = 1 to k nn(i) = n + 1 - i ´ n*(n-1)*(n-2)*....*(n+1-k) nk(i) = i ´ 1*2*3*...*k nextfor i = k to 1 step -1
for j = 1 to k temp = zdgys(nk(j), nn(i)) ´最大公约数 if temp > 1 then ´消除分子分母 ... 下一页