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
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 | jiangly | 3846 |
2 | tourist | 3799 |
3 | orzdevinwang | 3706 |
4 | jqdai0815 | 3682 |
5 | ksun48 | 3590 |
6 | Ormlis | 3533 |
7 | Benq | 3468 |
8 | Radewoosh | 3463 |
9 | ecnerwala | 3451 |
9 | Um_nik | 3451 |
# | User | Contrib. |
---|---|---|
1 | cry | 165 |
2 | -is-this-fft- | 160 |
2 | Qingyu | 160 |
4 | atcoder_official | 156 |
5 | Dominater069 | 155 |
6 | adamant | 154 |
7 | djm03178 | 151 |
8 | luogu_official | 149 |
9 | awoo | 147 |
10 | Um_nik | 146 |
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 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≤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