Add tags

Add tags to the following comment
グループ未定の数字の最初のものpは、まだ決まってないグループ(X)に。
Xの残りの(n-1)個は、残っている数字から、和が(s/n-p)になるものとする。
最後まで行ったらカウンタに1加算。
初めに戻る。

(ComplementやSubsetsは常にソートされている)

In[3]:= f[3]
Out[3]= 2

In[4]:= f[4]
Out[4]= 392(Core2 6700で0.06秒)

In[5]:= f[5]
Out[5]= 3245664(Core2 6700で690秒)
1
2
3
4
5
6
f[n_] := f[Range[n^2], n, Total@Range[n^2]/n]

f[in_, n_, s_] :=
  If[Length@in == n, 1,
    Total[f[Complement[Rest@in, #], n, s] & /@ (
    Select[Subsets[Rest@in, {n - 1}], First@in + Total@# == s &])]]

Add tags

The input will be splited to tags with space.

Index

Feed

Other

Link

Pathtraq

loading...