Test instructions
The number of the longest common subsequence >=n-1 after sorting the first k number in the full permutation of n
Thinking
Let's find out what the last possible results are, and then find out how many permutations can make up these results.
Set the arrangement to S
- S like,..., N, number =1
- S like ... i-1, J, I, ... j-1, j+1, ... n
- When J<=k is not present
- When j>k, number = (j-1)-k+1=j-k
- Sum up, number =\ (\sigma_{j=k+1}^{n}j-k\)
- S like,... i-1, i+1,. J,i,j+1..n
- When J<=k, the number =n-(k+1) +1=n-k
- When j>k, number = N (j+1) +1=n-j
- Sum up, number =\ (k (n-k) +\sigma_{j=k+1}^{n}n-j\)
- But S like,..., i+1,i,... is repeated, the number =n-(k+1) +1=n-k
- Results =1+k (n-k) + (n-k) ^2-(n-k) =1+ (n-1) (n-k)
And because each result can be composed of k!
So the final answer is [1+ (n-1) (n-k)]k! , K<=n
ICPC Shenyang Problem C