一、总结
组合数:choose(n,k) —— 从n个中选出k个
阶乘:factorial(k) —— k!
排列数:choose(n,k) * factorial(k)
幂:^
余数:%%
整数商:%/%
列出所有组合数矩阵:combn(x,n)
t(combn(x,n)) 转置
二、具体例子
choose(5,3) # 10
factorial(5) # 120
choose(5,3)*factorial(3) # 60
2^10 # 1024
10 %% 3 # 1
10 %/% 3 # 3
x <- 1:5
n <-3
combn(x,n)
/*
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,] 1 1 1 1 1 1 2 2 2 3
[2,] 2 2 2 3 3 4 3 3 4 4
[3,] 3 4 5 4 5 5 4 5 5 5
*/
t(combn(x,n))
/*
[,1] [,2] [,3]
[1,] 1 2 3
[2,] 1 2 4
[3,] 1 2 5
[4,] 1 3 4
[5,] 1 3 5
[6,] 1 4 5
[7,] 2 3 4
[8,] 2 3 5
[9,] 2 4 5
[10,] 3 4 5
*/
END 2018-11-26 11:07:27
请发表评论