コンピュータに数えさせました。
library(gtools)
n=5
r=10
c=3
perm=permutations(n,r,rep=T)
tail(perm)
g <- function(x) all(1:n %in% x)
system.time(g(perm[1:1e6,])) # fast
i=which(apply(perm,1,g)) # lengthy
perm5=perm[i,]
tail(perm5)
j=length(i)/factorial(5)
h <- function(x) max(table(x)) <= c
k=which(apply(perm5[1:j,],1,h))
length(k)
length(k)*factorial(5)
l=which(apply(perm5,1,h)) # lengthy
length(l)
答は>319の通り
> length(l)
[1] 3137400
面白い問題おしえて〜な 27問目
■ このスレッドは過去ログ倉庫に格納されています
336132人目の素数さん
2018/09/04(火) 12:28:51.00ID:7/9foHEp■ このスレッドは過去ログ倉庫に格納されています