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
# | User | Rating |
---|---|---|
1 | tourist | 3856 |
2 | jiangly | 3747 |
3 | orzdevinwang | 3706 |
4 | jqdai0815 | 3682 |
5 | ksun48 | 3591 |
6 | gamegame | 3477 |
7 | Benq | 3468 |
8 | Radewoosh | 3462 |
9 | ecnerwala | 3451 |
10 | heuristica | 3431 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | -is-this-fft- | 162 |
3 | Dominater069 | 160 |
4 | Um_nik | 158 |
5 | atcoder_official | 156 |
6 | djm03178 | 153 |
7 | adamant | 152 |
8 | luogu_official | 149 |
9 | awoo | 147 |
10 | TheScrasse | 146 |
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
Name |
---|
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