【问题标题】:Arrangement of sequence of 'n' numbers'n' 数字序列的排列
【发布时间】:2012-07-18 05:15:21
【问题描述】:

你可以用多少种方式排列一个“n”(1 到 n)个数字的序列,使得在其值所代表的索引处没有数字出现?

例如

1 can not be at first position
2 can not be at second position
.
.
n can not be at nth position

请给出一个通用的解决方案。也解决它为n = 6。 这不是家庭作业。

【问题讨论】:

  • 如果它走路像鸭子,说话像鸭子......你确定这不是家庭作业吗?
  • 如何以编程方式生成紊乱的问题已经dealt with previously here。严格来说,计算它们的公式是一个数学主题(请参阅我在 MathSE 上链接到此类问题的答案)。

标签: algorithm math permutation


【解决方案1】:

您想要无定点排列,也称为derangements。它们数量的公式比可能具有固定点的排列数量的公式稍微复杂一些。

【讨论】:

  • 非常轻微,最接近 n!/e 的整数。 Wikipedia 文章并没有清楚地解释这一点,尽管它指出紊乱的分数收敛到 1/e 并给出了 floor((n!/e) + (1/2)) 作为精确表达式。
【解决方案2】:

令 P(n) 为 n 数字的此类排列数。

For 123456....n
Cases are of the form

2*****
3*****
4*****
5*****
.
.
n*****

Now 1 can be anywhere at the rest (n-1) positions.
If 1 is put at the position of the number replacing it...

21****
3*1***
4**1**
.
.
n****1

then first and the replaced numbers are fixed.
Then total cases = (n-1) * P(n-2)

Else if
1 is also restricted not to be at a particular position (positions in above cases)
Then total cases = (n-1) * P(n-1)

所以

P(n) = (P(n-1) + P(n-2)) * (n-1)

P(1) = 0

和 P(2) = 1

【讨论】:

    【解决方案3】:

    n 事物的紊乱(无定点排列)数为 round(n!/e),其中 e 是自然对数的底。这里round 表示最接近的整数函数。这在 the Wikipedia article 中有所描述,但方式可以得到澄清。

    对于n = 6,很容易计算出有round(264.87...) = 265 混乱。

    实际上你已经问过a frequently covered question from MathSE

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-05
      • 2019-11-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多