Counting Disorders

from the wiki, a way to count violations,

Suppose there are n people, numbered 1, 2, ..., n. Let there be n hats also numbered 1, 2, ..., n. We need to find the number of ways in which no one gets a hat with the same number as his number. Let us assume that the first person takes hat i. There is an n - 1 way for the first person to make that choice. Now there are two possibilities, depending on whether the person I accept hat 1 in return:

Person I do not accept hat 1. This case is equivalent to solving the problem with n - 1 people and n - 1 heads: each of the remaining n - 1 people has exactly 1 forbidden choice from the remaining n - 1 hat (prohibited choice is hat 1). Person I take hat 1. Now the problem boils down to n - 2 faces and n - 2 hats.

This implies the following relationship:

!n = (n - 1) (!(n-1) + !(n-2))  

Here I do not understand the second part. I'm trying to think about such a problem,

NO.1: I am a man, so I can not take this hat. Therefore, I have option n-1. This reduces the problem with an n-1 character with an n-1 hat, which will be multiplied (n-1) times.

But I can not understand the second part of the recursive call. from the aisle, "man, I take hat 1", how ...? Is it not true that "I have banned hat 1"? Then, how will a person take hat 1. Otherwise, if "i forbidden hat is not 1", then this does not reduce to NO.1?

So more or less I find it difficult to understand this part of the recursive call,

!n = (n - 1) (!(n-1) + !(n-2))
                       *******
+4
source share
2 answers

f . f(n) n n . n-1. 1 i n-1. i - n-1 , n-2 ( i).

, i.

  • i 1
  • i 1, , ,

2 , i 1, . , i n-1, n-2, . , f (n-1) . 1 i 1. , , i 1 , , f (n-2),

, , (n-1) , f(n) = (n-1)(f(n-1) + f(n-2))

+3

:

  • N, 1- > i- > 1, N-2.
  • N, 1- > i- > j!= 1, N-1.

: 1- > i- > 1 - {1,..., n}, n-2, , {2, 3,..., i-1, + 1,..., n}, {1,..., n} 1- > i- > 1.

, , {2,..., n}, {1,..., n}, 1- > 1 . , {1,..., n}, 1- > 1, {2,..., n}, 1- > 1, i.

:

D (n) = sum (i = 2..n) (D (n-1) + D (n-2)) = (n-1) (D (n-1) + D (n- 2))

+1

All Articles