Блог пользователя zzzz-

Автор zzzz-, история, 7 лет назад, По-английски

We all know what a permutation is. So, I remember a good problem from school. Let P be a permutation of 1, 2, 3, .... n. We define the function f(P) as the number of positions where P[i] = i (also known as fixed points I think). What is the expect value of f :)

  • Проголосовать: нравится
  • +11
  • Проголосовать: не нравится

»
7 лет назад, скрыть # |
Rev. 7  
Проголосовать: нравится +9 Проголосовать: не нравится

I think there is a O(n) solution using dp, let dp[i]: number of ways that i numbers can arrangue that there isn't a p[j]=j, then your answer is $$$\sum\limits_{i=2}^{n} (n-i)*dp[i]*comb(n, i)/n! + 1/n!$$$, and $$$dp[i]=(i-1)*(dp[i-1]+dp[i-2]), 2 \leq i$$$

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +14 Проголосовать: не нравится

Let p(i) be the probability that i is a fixed point, then p = (n-1)!/n!. Using linearity of expectation, f(P) = sum of p(i)*1 = |P| * 1/|P| = 1

»
6 лет назад, скрыть # |
 
Проголосовать: нравится -105 Проголосовать: не нравится

ban