Hello codeforces community!!
On this occasion I bring up a combinatorics problem.
This is the problem:
How many permutations of length N exist such that the following holds: for each i (1 <= i < N) p[i+1] — p[i] != 1
Constants: 1 <= N <= 500
№ | Пользователь | Рейтинг |
---|---|---|
1 | jiangly | 3976 |
2 | tourist | 3815 |
3 | jqdai0815 | 3682 |
4 | ksun48 | 3614 |
5 | orzdevinwang | 3526 |
6 | ecnerwala | 3514 |
7 | Benq | 3482 |
8 | hos.lyric | 3382 |
9 | gamegame | 3374 |
10 | heuristica | 3357 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 170 |
2 | -is-this-fft- | 166 |
3 | Um_nik | 161 |
3 | atcoder_official | 161 |
5 | djm03178 | 157 |
6 | Dominater069 | 156 |
7 | adamant | 154 |
8 | luogu_official | 152 |
9 | awoo | 151 |
10 | TheScrasse | 147 |
Hello codeforces community!!
On this occasion I bring up a combinatorics problem.
This is the problem:
How many permutations of length N exist such that the following holds: for each i (1 <= i < N) p[i+1] — p[i] != 1
Constants: 1 <= N <= 500
Название |
---|
Auto comment: topic has been updated by Kanata18 (previous revision, new revision, compare).
I haven't proved my solution yet, but this should solve the task in $$$\mathcal{O}(n)$$$.
Basically, I though about decomposing the permutation into $$$k$$$ subarrays that each subarray satisfies the condition that the next term is +1 the last term. If this is possible, then this permutation is $$$k$$$-good We can look at this decomposition as also a permutation. We want the number of permutations that is $$$n$$$-good but not $$$n-1$$$-good. This makes me want to try out some inclusion-exclusion, similar to counting derangements. The exact expression is done by changing the formula bit-by-bit and compare with brute-force results.
It occurred to me to do it using: Connected Component DP (although I don't know how to implement it)
This problem is the exact same as CSES — Permutations II, although the constraints are $$$n \leq 5000$$$.
Note, this task could be solved in $$$O(n)$$$, you can check it on USACO Guide — Solution
Thank you very much for the material