Suppose we have given a permutation of length n. Can we find the count of a specific binary string of length n-1. Such that for each permutation p we increment the count of binary string b, where b[i]=='1' if p[i+1]>p[i] else '0' for each i from 0...n-2. For n=5 I have runned the bruteforce code
Code
Getting the output
result
Yes, but it's hard.
1776N - Count Permutations
Actually the solution in $$$O(n^2)$$$ is much easier. See this problem.
Let $$$dp_{i,j}$$$ be the number of permutations of length $$$i$$$ (of the elements $$$\{1, \dots, i\}$$$) such that the first $$$i-1$$$ constraints hold and $$$p_i = j$$$. When calculating $$$dp_{i+1,j}$$$, you are inserting $$$j$$$ at the end of the permutation, and elements in $$$[j, i]$$$ are mapped to $$$[j+1, i+1]$$$.
Thanks TheScrasse