ICPC Shenyang Problem C

Source: Internet
Author: User

Tags: line like Lin number ICP generation think repeat problem

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

Tags Index: