Skip to content

Instantly share code, notes, and snippets.

@pygman
Created August 30, 2016 03:04
Show Gist options
  • Save pygman/916b44db4218b42baae7b3f89c7c5eeb to your computer and use it in GitHub Desktop.
Save pygman/916b44db4218b42baae7b3f89c7c5eeb to your computer and use it in GitHub Desktop.
求排列组合数
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