怎么计算组合数?
projecteuler吧
全部回复
仅看楼主
level 7
酒尽望天 楼主
比如,我想从range(10)里抽取2个来组合,不排列,有好的算法吗,网上有人说只要6行就行了,不过每给出代码,求nx实现.
2012年09月06日 11点09分 1
level 6
到底是求出具体的合还是计算组合数啊?
2012年09月06日 13点09分 2
当然是具体的组合拉,组合数有公式嘛
2012年09月06日 14点09分
level 8
Ruby
(1..10).combination(2)
2012年09月07日 02点09分 4
死开。。。
2012年09月07日 05点09分
回复 xw_y_am :[顶]ruby万岁!
2012年09月08日 07点09分
回复 xw_y_am :[鬼脸]
2012年09月08日 11点09分
level 3
0..9的随机两个数组合的结果无非就是0..99,只要结果的话
list(range(100))
如果按照你的思路写算的话:
import itertools
list(itertools.permutations(range(10),2))
或者
[[(c,b) for b in range(10)]for c in range(10)]
2012年09月07日 04点09分 5
不能重复的
2012年09月07日 07点09分
level 10
是这个东西吗????
2012年09月07日 05点09分 6
递归。。。[揉脸][揉脸],求无递归版。
2012年09月07日 07点09分
回复 酒尽望天 : 无递归版不好做 m > 2 的啊。。。。
2012年09月07日 07点09分
回复 xw_y_am :[揉脸]为神马itertools里的东西都是递归出来的,而且返回的都是元组,一旦数量大时就卡在那了,之前不记得哪题,用perturbation,结果直接卡住。。。
2012年09月07日 07点09分
回复 酒尽望天 : 转换一下不就好了嘛。。。
2012年09月07日 07点09分
level 10
[抛媚眼][抛媚眼]

2012年09月07日 08点09分 7
1