The only way so solve it that I've found is to use https://en.wikipedia.org/wiki/Rencontres_numbers and calcuate
, but I don't like that. Is there other way? Can we use inclusion-exclusion formula to calculate it?
| № | Пользователь | Рейтинг |
|---|---|---|
| 1 | Benq | 3792 |
| 2 | VivaciousAubergine | 3647 |
| 3 | Kevin114514 | 3603 |
| 4 | jiangly | 3583 |
| 5 | turmax | 3559 |
| 6 | tourist | 3541 |
| 7 | strapple | 3515 |
| 8 | ksun48 | 3461 |
| 9 | dXqwq | 3436 |
| 10 | Otomachi_Una | 3413 |
| Страны | Города | Организации | Всё → |
| № | Пользователь | Вклад |
|---|---|---|
| 1 | Qingyu | 157 |
| 2 | adamant | 153 |
| 3 | Um_nik | 146 |
| 3 | Proof_by_QED | 146 |
| 5 | Dominater069 | 145 |
| 6 | errorgorn | 141 |
| 7 | cry | 139 |
| 8 | YuukiS | 135 |
| 9 | TheScrasse | 134 |
| 10 | chromate00 | 133 |
The only way so solve it that I've found is to use https://en.wikipedia.org/wiki/Rencontres_numbers and calcuate
, but I don't like that. Is there other way? Can we use inclusion-exclusion formula to calculate it?
| Название |
|---|



Why don't you like that?
because I don't understand that
What exactly don't you understand?
Obvious formula, he just troll
Yes we can. Notice that D(N, k) = C(N, k)·!(N - k), and derangement of (N - k) can be calculated this way
Please elaborate
What does "fixed points" mean?
ai = i
There is another solution involving dynamic programming and constructing permutations.
First, consider the following way of constructing all permutations of length n from all permutations of length (n - 1). Suppose we have a permutation of length (n - 1), for example, n = 6 and the permutation is
a b c d e. Put the new element n at the back of the permutation. Then, swap the new last element with one of the elements, including itself. We get n different permutations:Note that different permutations
a b c d eproduce different permutations of length 6. So, this process allows to construct all permutations of length n from all permutations of length (n - 1).Now, look what happens with the fixed points during this process. Let there be k fixed points in the permutation
a b c d e. Clearly, 0 ≤ k ≤ (n - 1).If we swap n with n, the number of fixed points increases by 1 (all the fixed points from
a b c d eplus the new element n).If we swap n with a fixed point (k possibilities), the number of fixed points decreases by 1.
If we swap n with an element which is already not in its place ((n - 1) - k possibilities), the number of fixed points stays constant.
We can now formulate a “forward” dynamic programming approach. If we know D(n - 1, k) = x, it contributes:
x to D(n, k + 1),
x·k to D(n, k - 1) and
x·((n - 1) - k) to D(n, k).
The “backward” dynamic programming solution (of the form D(n, k) = ...) can also be formulated.
The problem of counting permutations with k fixed point is addressed in the book generatingfunctionology, as an example of the interpretation of the inclusion-exclusion principle in terms of generating functions.
The approach yields the result that for a given n, if ak is the number of permutations of size n with exactly k fixed points, then its ordinary power series generating function is
.
This gives the formula