Created
August 30, 2016 03:04
-
-
Save pygman/916b44db4218b42baae7b3f89c7c5eeb to your computer and use it in GitHub Desktop.
求排列组合数
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def combcount(n,r): | |
f = lambda n,r:n*f(n-1,r) if n>r else 1 | |
return f(n,n-r)/f(r,0) | |
def permcount(n,r): | |
f = lambda n,r:n*f(n-1,r) if n>r else 1 | |
return f(n,n-r) | |
# 附带使用python的itertools求全排列、全组合函数 | |
import itertools as it | |
list(it.permutations([1,2,3,4,5,6],4)) | |
list(it.combinations([1,2,3,4,5,6],4)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment